From patchwork Mon Jun 24 13:14:38 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: 807039 Delivered-To: patch@linaro.org Received: by 2002:a5d:508d:0:b0:362:4979:7f74 with SMTP id a13csp1878609wrt; Mon, 24 Jun 2024 06:18:59 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWrbn5dIkN/kQTbHVKp9vQBkNA5Oi07AJmiKnaHunkzmmxVBgh0s7cpdZYtgQXPy1bcS1c2oO8g1n0eK9earha8 X-Google-Smtp-Source: AGHT+IFbXY8jYui4u0yUnokbZ0ETjeRNUrjig7U5lVS6n4kkDW4CT4SmNkKy3+Uy8S9kgM+cPvlE X-Received: by 2002:a05:620a:1909:b0:795:5465:5989 with SMTP id af79cd13be357-79be6e507e0mr537548385a.27.1719235138888; Mon, 24 Jun 2024 06:18:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719235138; cv=none; d=google.com; s=arc-20160816; b=0CS1XX3dB9BTcWMryWB30LY7g+v/8slq7DZtfLQqCXHoljHc2uh7NnByZdchiJha49 A73ltJ9XHh0ETXX8OMieT4B6YoLlRcAkJ96EaoxFD2n8LCLmXzObk+0EaV6uDJZYA3sy gHgCTQ2ZW8Tvao8Yc8TfjXJBTwTn/YiDKht8miujhfXXVNIwYrnQ1P2AR7EmnIvino9b HsiLlKyiO/2Zvsvqwon82IeJZE1KjJ2ymFT2pX3+LDFXr1Kgbtw1leC/XihnhaiJMTuU AGhDumbmXlS+r0Aj2j1HoP4v5ZRfFelTAGizqZm09tSCtmw5+jfNvp8bVphhRnSU3VEt y1MQ== 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=+OyvAZYAFCHsIdySGDiXeFQ2F3N56N52JzU6FXve/Tk=; fh=/TyiCVzPJVYkT4NtrOYZRXAcrkaiLXA/rwqp4QqIc5M=; b=hRmFfq16XnAlx2YRL0pKYyWKtQGhkPqfHCbId7RPcCvdItFNOF7J27P1OTNWfiKZvB 0j0hYJcu8qm1qs4lGPpLZEGe/3yiZIfNZfFOU2avqm0cketHJftUFXZCrGMr6lUbqg1T mgI5s7I1ncsjy6OFSSR6YI/pU/kc7iCJ2/u7vpEKFd0MR26K9Mgz/AWQm8vW0nNZxIW4 b/xS6eT8wFfp8HPolFqkR3uKGrPPuvf7Srtunt/cCfw277YChjPU3JoefwMDji1BjTXB 2SEcg4fRaNPpFduy12b3o/B8VO2emvIW6Rp7UwW6GDpcqts07LMGrYo/ziSKTn5pxcXB 5jXg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DzUU0xic; 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-79bce8ab673si853416085a.215.2024.06.24.06.18.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 24 Jun 2024 06:18:58 -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=DzUU0xic; 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 1sLjZ9-0005LR-JA; Mon, 24 Jun 2024 09:17:06 -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 1sLjYU-0004Vq-Er for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:16:31 -0400 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sLjYS-0005c3-6z for qemu-devel@nongnu.org; Mon, 24 Jun 2024 09:16:21 -0400 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2ec4eefbaf1so32206141fa.1 for ; Mon, 24 Jun 2024 06:16:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719234976; x=1719839776; 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=+OyvAZYAFCHsIdySGDiXeFQ2F3N56N52JzU6FXve/Tk=; b=DzUU0xiczFjZbc9WgaPziF66c2woNd8KtcRbC03A9JHkQHZVSEH+VU0YH5omWSgRWr njhyl6h0yZVWdsPwP4ZxRuY9De3ltdIqWaMGPsGSZcYxse9V360AL03A2gLhCoJ/4A09 lfU+K5bVJK9OjM5B2DL0baVC3FMDFS4yjGL9n0A/YSF2KCq9uX96AW4RKp3KJUenwziV Qm6bVyIx6pVL6uUkbfBb2h2y55nl3DoIWylVOiTXrxAClRZsECQK5Yju6Uk9X3EVtnPn oeT4BUtXnZr1C6MRJjnK2YVyM1RzNEMT50ZOjpgrY+ylOhxZ61Pc5bb6LCm4qe34Q3ox RqZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234976; x=1719839776; 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=+OyvAZYAFCHsIdySGDiXeFQ2F3N56N52JzU6FXve/Tk=; b=WX3M8uRmzf010mGhec5x4D/oAIcu0P5VUMOPvJWUTqq+Cl9D+h9UzUhLpY2DDyIpKP w4S8won5JL+mo1qqUNLgq3NalbIgZ2HOSiqR6VAWn2jfc11Yq3P5UWeKCveEatY09CLj uGEeErGmdig23tg0014+x5v3MHQCnZGLTIwnsFWLdVWQcEhZ6OZJgC55B1Aj4gJj9xxa ochFoifHflbhcg4dN/jkiN+AdE6NQokj390CLzPD6CMdgSE54AP54JxtuCtJsuPLZwc7 3bAw8ajo8lF1EPBdpGsTnA7I1jFyKR0bCN2uVxnNA+gEH+SPjgQBLcc/TSrF92edHhYY BDaQ== X-Gm-Message-State: AOJu0Ywf3z7qKiBjq3YyjNw+iL0TUrFUC0K4QPEHBQXwl6XcNlmKzNJg aftoApYQJozIZWbybwkt5nVvkpTffAArEclCVfYlzuLKLS53zCp2+zrjULczPUwziEzfT7McTI3 u X-Received: by 2002:a2e:b788:0:b0:2ec:4487:6a8f with SMTP id 38308e7fff4ca-2ec5b3d4ab1mr26520821fa.37.1719234975804; Mon, 24 Jun 2024 06:16:15 -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 ffacd0b85a97d-366388c41b0sm10007103f8f.44.2024.06.24.06.16.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Jun 2024 06:16:15 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= Subject: [PULL 17/19] hw/sd/sdcard: Add sd_invalid_mode_for_cmd to report invalid mode switch Date: Mon, 24 Jun 2024 15:14:38 +0200 Message-ID: <20240624131440.81111-18-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240624131440.81111-1-philmd@linaro.org> References: <20240624131440.81111-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::232; envelope-from=philmd@linaro.org; helo=mail-lj1-x232.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 Having the mode switch displayed help to track incomplete command implementations. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Cédric Le Goater Tested-by: Cédric Le Goater Message-Id: <20240621080554.18986-19-philmd@linaro.org> --- 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 3e4eb656e1..969340e5cb 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -178,6 +178,17 @@ static const char *sd_version_str(enum SDPhySpecificationVersion version) return sdphy_version[version]; } +static const char *sd_mode_name(enum SDCardModes mode) +{ + static const char *mode_name[] = { + [sd_inactive] = "inactive", + [sd_card_identification_mode] = "identification", + [sd_data_transfer_mode] = "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[] = { @@ -1018,6 +1029,15 @@ static sd_rsp_type_t sd_invalid_state_for_cmd(SDState *sd, SDRequest req) return sd_illegal; } +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", @@ -1156,18 +1176,14 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) break; case 6: /* CMD6: SWITCH_FUNCTION */ - switch (sd->mode) { - case sd_data_transfer_mode: - sd_function_switch(sd, req.arg); - sd->state = sd_sendingdata_state; - sd->data_start = 0; - sd->data_offset = 0; - return sd_r1; - - default: - break; + if (sd->mode != sd_data_transfer_mode) { + return sd_invalid_mode_for_cmd(sd, req); } - break; + sd_function_switch(sd, req.arg); + sd->state = sd_sendingdata_state; + sd->data_start = 0; + sd->data_offset = 0; + return sd_r1; case 7: /* CMD7: SELECT/DESELECT_CARD */ rca = sd_req_get_rca(sd, req); @@ -1291,33 +1307,24 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) case 13: /* CMD13: SEND_STATUS */ rca = sd_req_get_rca(sd, req); - switch (sd->mode) { - case sd_data_transfer_mode: - if (!sd_is_spi(sd) && sd->rca != rca) { - return sd_r0; - } - - return sd_r1; - - default: - break; + if (sd->mode != sd_data_transfer_mode) { + return sd_invalid_mode_for_cmd(sd, req); } - break; + if (!sd_is_spi(sd) && sd->rca != rca) { + return sd_r0; + } + + return sd_r1; case 15: /* CMD15: GO_INACTIVE_STATE */ - rca = sd_req_get_rca(sd, req); - switch (sd->mode) { - case sd_data_transfer_mode: - if (sd->rca != rca) - return sd_r0; - - sd->state = sd_inactive_state; - return sd_r0; - - default: - break; + if (sd->mode != sd_data_transfer_mode) { + return sd_invalid_mode_for_cmd(sd, req); } - break; + rca = sd_req_get_rca(sd, req); + if (sd->rca == rca) { + sd->state = sd_inactive_state; + } + return sd_r0; /* Block read commands (Class 2) */ case 16: /* CMD16: SET_BLOCKLEN */