From nobody Mon Nov 25 01:42:55 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=1719506427; cv=none; d=zohomail.com; s=zohoarc; b=A9+NIUSQy10qD33JZx3vjWIwhz+KAjU9yU1a2SOqermtQz0L6Eb5lMuprA4IbY1X5gtdRinZGhiMLbppGhYZ4/ogUN3VCmtw0kj00HbrHjWjRnHbqNOMzHDYFw+pl+bawmG1PzUtAiwnBdkh30qddCijKwkFkjbwflREwe5zCak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1719506427; 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=O7w8iWHuHLj1qqdMh1OWVQD6LygpPO88gA0me6KT8+s=; b=k3Ouph5hviS/j0r1rMKHDtF7C2KNHOm2cftPXFRz6ms68D2Jh1aoc/bxMK0lKfFYTrODtGP9Lai5v97eq5mxvKdcw5c9zdh9cwXa0VB9FFCEgPogdj44dvmTtrTG7QQBicMGOa3GfqrmVvgJEALMncA3Q7sAPMW+fjOYi3+9SVM= 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 1719506427388154.8728885669783; Thu, 27 Jun 2024 09:40:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sMsAC-0002Jm-MG; Thu, 27 Jun 2024 12:40:01 -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 1sMsAA-0002Cn-GI for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:39:58 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sMsA7-0006wM-BE for qemu-devel@nongnu.org; Thu, 27 Jun 2024 12:39:58 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-42122ac2f38so13077225e9.1 for ; Thu, 27 Jun 2024 09:39:54 -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 5b1f17b1804b1-424c82519c8sm77443365e9.16.2024.06.27.09.39.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 27 Jun 2024 09:39:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719506393; x=1720111193; 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=O7w8iWHuHLj1qqdMh1OWVQD6LygpPO88gA0me6KT8+s=; b=xulGlB35WaTYVPJLVTnASDz/Udifw7yu7EcAf/k8MV/U8fdDRRaHqh/g3NC41JHlqK u+S+gix1r+k8ZM/CQdhGyyda7YPZ1YKPXWbwfsZXJVhtzIFEcrgxBbiDQSXP6IzzKOZ5 wWPwQX5Z/umc/UHqyhBeMDqUdJG3NWckRZBg1d++fCsjokVSd8XBfwLm8pjxvX+VQ1VU DLHSnbKZhFp7fI4me+Eo0yMeCdzt1uqZ2pC30L+F+m2Yf8L27SyeTNvzW67ubxrz6rXU aQCU3Wt3dek9BNZvT7c0WUTQBCrGV8cOODhd3NtH9TQPOoyJp7oHzEp6rTMtEMUktzeV timg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719506393; x=1720111193; 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=O7w8iWHuHLj1qqdMh1OWVQD6LygpPO88gA0me6KT8+s=; b=GJwhaRdVqVHXt1vc3XzOe/6xSXinAapHss7YXI6Nb7rZnUpAD2ilKheLQ/I4Gf8HXU ZpOurDl6c+e5UN6A5OgBKtJsIgxK8OOndb5r4+Vmsb/qXg9wPfqpAJ7pB2b7iFvRKG7x hhWbFGYzKWYR+XxcIREiJf8m1tW+hBrbbNwEfFk3/1+AdRJxxjlvbTA+mdSFEFdOJ7er y30v6npYof704cZzw8KxAyHhnzvqWOwA9zvDjjRxR+diS1aBl5RWeK4WTmGQxlsYB1rE abAJ8nQI9LrxVQWMIoPF/AHKGJ+CwxmFsBZey1BcEE3lM3/HQ+ZnhDFw3wrg8E2dlVlW GNGg== X-Gm-Message-State: AOJu0YyEPUABeC7Sp/DAZ/504xBBUSLip+CWd/A0Xo355i480l0159al N/GzL2C2SwTqudbnsVh8leB5GYPFS2EJyLv4FzCeLRF294CYDCXP8sIxR3zZfcNE/hIJPOlItDp W3wc= X-Google-Smtp-Source: AGHT+IHz4JjI/2GXWRzm1fXsk+9MIfvigT1nS3xwfMxaU1tdycBy3ddrHKtK8IfTzbTauNVuzP0kww== X-Received: by 2002:a05:600c:4a06:b0:421:8234:9bb4 with SMTP id 5b1f17b1804b1-42563126c2dmr32558455e9.19.1719506393602; Thu, 27 Jun 2024 09:39:53 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Joel Stanley , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Francisco Iglesias , qemu-block@nongnu.org, Sai Pavan Boddu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Bin Meng , Luc Michel Subject: [PATCH 06/11] hw/sd/sdcard: Store command class in SDProto Date: Thu, 27 Jun 2024 18:38:38 +0200 Message-ID: <20240627163843.81592-7-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240627163843.81592-1-philmd@linaro.org> References: <20240627163843.81592-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::32d; envelope-from=philmd@linaro.org; helo=mail-wm1-x32d.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=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: 1719506429205100004 Store the command class altogether with the other command fields (handler, name and type). Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/sd/sd.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index c4cc48926d..a816493d37 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -95,6 +95,7 @@ typedef sd_rsp_type_t (*sd_cmd_handler)(SDState *sd, SDRe= quest req); typedef struct SDProto { const char *name; struct { + const unsigned class; const sd_cmd_type_t type; const char *name; sd_cmd_handler handler; @@ -352,13 +353,6 @@ static void sd_set_mode(SDState *sd) } } =20 -static const int sd_cmd_class[SDMMC_CMD_MAX] =3D { - 0, 0, 0, 0, 0, 9, 10, 0, 0, 0, 0, 1, 0, 0, 0, 0, - 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 6, 6, 6, 6, - 5, 5, 10, 10, 10, 10, 5, 9, 9, 9, 7, 7, 7, 7, 7, 7, - 7, 7, 10, 7, 9, 9, 9, 8, 8, 10, 8, 8, 8, 8, 8, 8, -}; - static uint8_t sd_crc7(const void *message, size_t width) { int i, bit; @@ -1306,7 +1300,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) sd->multi_blk_cnt =3D 0; } =20 - if (sd_cmd_class[req.cmd] =3D=3D 6 && FIELD_EX32(sd->ocr, OCR, CARD_CA= PACITY)) { + if (sd->proto->cmd[req.cmd].class =3D=3D 6 && FIELD_EX32(sd->ocr, OCR, + CARD_CAPACITY)) { /* Only Standard Capacity cards support class 6 commands */ return sd_illegal; } @@ -1891,6 +1886,8 @@ static sd_rsp_type_t sd_app_command(SDState *sd, =20 static bool cmd_valid_while_locked(SDState *sd, unsigned cmd) { + unsigned cmd_class; + /* Valid commands in locked state: * basic class (0) * lock card class (7) @@ -1905,7 +1902,12 @@ static bool cmd_valid_while_locked(SDState *sd, unsi= gned cmd) if (cmd =3D=3D 16 || cmd =3D=3D 55) { return true; } - return sd_cmd_class[cmd] =3D=3D 0 || sd_cmd_class[cmd] =3D=3D 7; + if (!sd->proto->cmd[cmd].handler) { + return false; + } + cmd_class =3D sd->proto->cmd[cmd].class; + + return cmd_class =3D=3D 0 || cmd_class =3D=3D 7; } =20 int sd_do_command(SDState *sd, SDRequest *req, @@ -2273,22 +2275,22 @@ void sd_enable(SDState *sd, bool enable) static const SDProto sd_proto_spi =3D { .name =3D "SPI", .cmd =3D { - [0] =3D { sd_spi, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, - [1] =3D { sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, + [0] =3D {0, sd_spi, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, + [1] =3D {0, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, }, .acmd =3D { - [41] =3D { sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, + [41] =3D {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, }, }; =20 static const SDProto sd_proto_sd =3D { .name =3D "SD", .cmd =3D { - [0] =3D { sd_bc, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, - [2] =3D { sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, - [3] =3D { sd_bcr, "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_= ADDR}, - [19] =3D { sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLO= CK}, - [23] =3D { sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, + [0] =3D {0, sd_bc, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, + [2] =3D {0, sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, + [3] =3D {0, sd_bcr, "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_= ADDR}, + [19] =3D {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLO= CK}, + [23] =3D {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, }, }; =20 --=20 2.41.0