From patchwork Tue Sep 26 10:00:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 726951 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CED3AE7D273 for ; Tue, 26 Sep 2023 10:02:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234114AbjIZKC0 (ORCPT ); Tue, 26 Sep 2023 06:02:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233494AbjIZKCU (ORCPT ); Tue, 26 Sep 2023 06:02:20 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CE16126 for ; Tue, 26 Sep 2023 03:02:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1695722533; x=1727258533; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xMSsDN0pdJvWEB/9ETHhWBHk694ynlb0lpBF4/28UYY=; b=FmB+DCFPSUKzHGz13Y8U65UDa8rjyG9zfCcl9evl/n2DUFS/7p7EaXh+ aQRcQK8sQhFOVEzLONo+tYU3DRYARKZX81WTLrOJH+gecSNzdx182J9oM FxiBatJziTTErZc5qTKP/kFqB6iD3tsXGpdT+u8+TMIoQZ79mjjDhfAC8 Wa4s2ab6iET9/dqeap0lJiqpWAXOLnCsH3h+CdWYlQ8CLjOcUFPje+ens NjyXq87qc4n7tod1T4XaOhYj01gWM3girjg0vGTSQu0Om5YXYe6pcrS2T zkms4zuppnu1WyivQ7wb53WRnGB5NZK/VDb6U/X/JCo8Az258la7lGi4/ A==; X-CSE-ConnectionGUID: iV+6TmpJRKOyeruQCX6BFA== X-CSE-MsgGUID: HfT1YmTERn274I1IIkXnbw== X-IronPort-AV: E=Sophos;i="6.03,177,1694707200"; d="scan'208";a="245305991" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 26 Sep 2023 18:02:13 +0800 IronPort-SDR: R+oDH55MM9/NOHFoMpDha3QOPFfYVP0gvbiALVu36UHDxHgVsT5LeAhLfosIRviZCBMnHISGV8 H9f/s+T08vRzddccUlW4IJhP1Apr+qBycOTqc4S/6Zng223RFjB5nzX2y7m3Uz0Bnd/v2MKKFU bLuuAyF7p9T0uY1Z5QM0GMy3xpDCRnNlhqjCYGE6U2uVfU2L3jC6Unh6hiwObLysNw+hvUNIk2 a5TdLgjK3MDDDJ9cCxoTASep/BNYdNcRcMdmra8bh3LtBzOSNnwyiLKo9lzAX9kbXRfDF/ZTkZ 9pw= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 26 Sep 2023 02:09:00 -0700 IronPort-SDR: ibOAdgs/elRzxw8K1nQJrsqdJrO+ESibgrQeVjchV9qM/uYAqX3j5vJ6CG0ShCJJwKEOTMDQzm Dlm7LCSFQnI3cNhwctqwvJsqPdBLQBbESv8atP7blZ2PVC3txF9WoMVdxe97nay9Eu5kfw3vC7 39e8FZKOvSlEdMYit/KxTQpXuxLoQqWitTdhekqXRZFMF6rdaGMY0Dj1a+OSyHHQFTBvJtL5iI 3k36MS/YkpL+eqzT5JMNLqwkc+UQJGLZkofVsy/3d+zoWPnYP8EXZvrXOtBPb3B5oAHSdJyhRe Z4s= WDCIronportException: Internal Received: from avri-office.ad.shared (HELO avri-office.sdcorp.global.sandisk.com) ([10.45.31.142]) by uls-op-cesaip02.wdc.com with ESMTP; 26 Sep 2023 03:02:13 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Avri Altman Subject: [PATCH 1/5] mmc-utils: lsmmc: Reuse do_read_reg Date: Tue, 26 Sep 2023 13:00:02 +0300 Message-Id: <20230926100006.1789276-2-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230926100006.1789276-1-avri.altman@wdc.com> References: <20230926100006.1789276-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org All 3 register parsing: CID, CSD, and CSR follow the same structure - reuse it instead of duplicating the code 3 times. No functional change. Signed-off-by: Avri Altman --- lsmmc.c | 59 +++++++++++++++++++-------------------------------------- 1 file changed, 19 insertions(+), 40 deletions(-) diff --git a/lsmmc.c b/lsmmc.c index 54c3167..85779bb 100644 --- a/lsmmc.c +++ b/lsmmc.c @@ -2373,7 +2373,6 @@ int lsmmc_main(struct config *config, int argc, char **argv) { int ret; - memset(config, 0, sizeof(*config)); config->mmc_ids = calloc(IDS_MAX, sizeof(char *)); config->sd_ids = calloc(IDS_MAX, sizeof(char *)); if (!config->mmc_ids || !config->sd_ids) { @@ -2395,71 +2394,51 @@ void lsmmc_free(struct config *config) free(config->dir); } -int do_read_csd(int argc, char **argv) +static int do_read_reg(int argc, char **argv, enum REG_TYPE reg) { - struct config config; + struct config cfg = {}; int ret; - if (argc != 2 && argc != 3) { - fprintf(stderr, "Usage: Print CSD data from .\n"); - exit(1); - } - - ret = lsmmc_main(&config, argc, argv); + ret = lsmmc_main(&cfg, argc, argv); if (ret) goto out; - if (config.dir) - ret = process_dir(&config, CSD); + if (cfg.dir) + ret = process_dir(&cfg, reg); out: - lsmmc_free(&config); + lsmmc_free(&cfg); return ret; + } -int do_read_cid(int argc, char **argv) +int do_read_csd(int argc, char **argv) { - struct config config; - int ret; - if (argc != 2 && argc != 3) { - fprintf(stderr, "Usage: Print CID data from .\n"); + fprintf(stderr, "Usage: Print CSD data from .\n"); exit(1); } - ret = lsmmc_main(&config, argc, argv); - if (ret) - goto out; - - if (config.dir) - ret = process_dir(&config, CID); + return do_read_reg(argc, argv, CSD); +} -out: - lsmmc_free(&config); +int do_read_cid(int argc, char **argv) +{ + if (argc != 2 && argc != 3) { + fprintf(stderr, "Usage: Print CID data from .\n"); + exit(1); + } - return ret; + return do_read_reg(argc, argv, CID); } int do_read_scr(int argc, char **argv) { - struct config config; - int ret; - if (argc != 2 && argc != 3) { fprintf(stderr, "Usage: Print SCR data from .\n"); exit(1); } - ret = lsmmc_main(&config, argc, argv); - if (ret) - goto out; - - if (config.dir) - ret = process_dir(&config, SCR); - -out: - lsmmc_free(&config); - - return ret; + return do_read_reg(argc, argv, SCR); } From patchwork Tue Sep 26 10:00:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 726621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F3C9E7D273 for ; Tue, 26 Sep 2023 10:02:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234317AbjIZKCb (ORCPT ); Tue, 26 Sep 2023 06:02:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234206AbjIZKCa (ORCPT ); Tue, 26 Sep 2023 06:02:30 -0400 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF4D9101 for ; Tue, 26 Sep 2023 03:02:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1695722543; x=1727258543; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7dYijs1ozuN5Cpqy9z6FqV0jUZ7L65azGz7G9f1Ld1c=; b=F/ya5l/Uq7dmFVrk3MYTv6lIU+HJF7Jnf9JUcW3ZMQR/Ccf629idCW2S EAdQJIqqQGwKoJqgjshmoOLBacFiJgStTrFvLg4u0C6M5GIqUbFh6yDO6 hw3pI9trl2gDgWJCGGw4Z4bdbaglCtG8E79aOs8KFmmj6w34hNV4xVoNv jslsFSI8RvzkzfsZgYqjE+r6WddnyoKtVO/Y4JpZl8pfn71DpAicCgiSx yq8Uub8Y9tm+pZA5J1BEXUatMa3xZPo3VreMT5jT5Gjss0m3KARUqkHNk KeNoBoYNqpqAABXzSB7TwW+9sbasuSIDbI2IYmHTdkcIG8WAnEKSBuD3Q Q==; X-CSE-ConnectionGUID: LKNPJGysSNi/dqr9S3DOVA== X-CSE-MsgGUID: St0U1tEbSfyPJMXe9Eb+Xg== X-IronPort-AV: E=Sophos;i="6.03,177,1694707200"; d="scan'208";a="357062215" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 26 Sep 2023 18:02:23 +0800 IronPort-SDR: a8zySrVj+toqDVrwE7nQskHW+d4L32PiqSw36T2bimyJ/k47SkjNBWtsK2A/ctgAY6vrPs62zR byiNPCHE5B0fh2W9Fx50S0+NsgkNURvMRyCVzkjkTM64f47NVbQ5WhKChsB8oe4mIN4W6BLxEk /RGCBlTMqko7MRsnstEuVUs1R0cK4VOLJk0UBx52pWd4QgqE0VGtHVsJp7btN3tqonVPlsFqBr zKQX2aJbOnJyX1pRRdqB+zVh8ypY8O9HNmi4zpMTqd9GMDhAm1/ug8bvxI61DXXhK6+nWxZc+K zko= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 26 Sep 2023 02:09:08 -0700 IronPort-SDR: cKRiE4N92Bl/2oOCKmIPLdVXjYuR/n35HmoQ5sFRMKVOD5lhDQm+kuprSA0IDEYkSKI5KLR/ZF Lq5mHG6MQPg/5V1iN871on6MX4P3TlaErttLaf/ClTEeGMe8Vdf7Sw1fxJR2UIkYpBw8fFiPzk pLx0eiyfU79JLh7FFJC+imsEAWmdl9Kozz69SZebQa0nqsIdQxyuvvv7MDQlmQ0VR4+qq1l8eI Ae8AiPsNoT3nrrtgzeIei/qKk2zskEpYMQGRJJdLHMsw/9hYP0RGouexGdVu3yci0YrrIDLRIe 5BM= WDCIronportException: Internal Received: from avri-office.ad.shared (HELO avri-office.sdcorp.global.sandisk.com) ([10.45.31.142]) by uls-op-cesaip02.wdc.com with ESMTP; 26 Sep 2023 03:02:21 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Avri Altman Subject: [PATCH 2/5] mmc-utils: lsmmc: Simplify prinitng manufacturer name Date: Tue, 26 Sep 2023 13:00:03 +0300 Message-Id: <20230926100006.1789276-3-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230926100006.1789276-1-avri.altman@wdc.com> References: <20230926100006.1789276-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org We used to have this odd way of printing the manufacturer name. To that end we cached the entire database beforehand which is completely useless. While at it, get rid of some more redundant code. Signed-off-by: Avri Altman --- lsmmc.c | 150 ++++++++++++++------------------------------------------ 1 file changed, 37 insertions(+), 113 deletions(-) diff --git a/lsmmc.c b/lsmmc.c index 85779bb..7e3165a 100644 --- a/lsmmc.c +++ b/lsmmc.c @@ -53,16 +53,19 @@ #define MASK(high, low) (MASKTOBIT0(high) & ~MASKTOBIT0(low - 1)) #define BITS(value, high, low) (((value) & MASK((high), (low))) >> (low)) #define IDS_MAX 256 +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +enum bus_type { + MMC = 1, + SD, +}; struct config { char *idsfile; char *dir; bool verbose; - int interfaces; - char **interface; - char **mmc_ids; - char **sd_ids; + enum bus_type bus; char *type; char *cid; char *csd; @@ -78,189 +81,157 @@ enum REG_TYPE { }; struct ids_database { - char *type; int id; char *manufacturer; }; -struct ids_database database[] = { +static struct ids_database sd_database[] = { { - .type = "sd", .id = 0x01, .manufacturer = "Panasonic", }, { - .type = "sd", .id = 0x02, .manufacturer = "Toshiba/Kingston/Viking", }, { - .type = "sd", .id = 0x03, .manufacturer = "SanDisk", }, { - .type = "sd", .id = 0x08, .manufacturer = "Silicon Power", }, { - .type = "sd", .id = 0x18, .manufacturer = "Infineon", }, { - .type = "sd", .id = 0x1b, .manufacturer = "Transcend/Samsung", }, { - .type = "sd", .id = 0x1c, .manufacturer = "Transcend", }, { - .type = "sd", .id = 0x1d, .manufacturer = "Corsair/AData", }, { - .type = "sd", .id = 0x1e, .manufacturer = "Transcend", }, { - .type = "sd", .id = 0x1f, .manufacturer = "Kingston", }, { - .type = "sd", .id = 0x27, .manufacturer = "Delkin/Phison", }, { - .type = "sd", .id = 0x28, .manufacturer = "Lexar", }, { - .type = "sd", .id = 0x30, .manufacturer = "SanDisk", }, { - .type = "sd", .id = 0x31, .manufacturer = "Silicon Power", }, { - .type = "sd", .id = 0x33, .manufacturer = "STMicroelectronics", }, { - .type = "sd", .id = 0x41, .manufacturer = "Kingston", }, { - .type = "sd", .id = 0x6f, .manufacturer = "STMicroelectronics", }, { - .type = "sd", .id = 0x74, .manufacturer = "Transcend", }, { - .type = "sd", .id = 0x76, .manufacturer = "Patriot", }, { - .type = "sd", .id = 0x82, .manufacturer = "Gobe/Sony", }, { - .type = "sd", .id = 0x89, .manufacturer = "Unknown", }, +}; + +static struct ids_database mmc_database[] = { { - .type = "mmc", .id = 0x00, .manufacturer = "SanDisk", }, { - .type = "mmc", .id = 0x02, .manufacturer = "Kingston/SanDisk", }, { - .type = "mmc", .id = 0x03, .manufacturer = "Toshiba", }, { - .type = "mmc", .id = 0x05, .manufacturer = "Unknown", }, { - .type = "mmc", .id = 0x06, .manufacturer = "Unknown", }, { - .type = "mmc", .id = 0x11, .manufacturer = "Toshiba", }, { - .type = "mmc", .id = 0x13, .manufacturer = "Micron", }, { - .type = "mmc", .id = 0x15, .manufacturer = "Samsung/SanDisk/LG", }, { - .type = "mmc", .id = 0x37, .manufacturer = "KingMax", }, { - .type = "mmc", .id = 0x44, .manufacturer = "ATP", }, { - .type = "mmc", .id = 0x45, .manufacturer = "SanDisk Corporation", }, { - .type = "mmc", .id = 0x2c, .manufacturer = "Kingston", }, { - .type = "mmc", .id = 0x70, .manufacturer = "Kingston", }, { - .type = "mmc", .id = 0xfe, .manufacturer = "Micron", }, }; + /* Command line parsing functions */ void usage(void) { @@ -310,47 +281,18 @@ int parse_opts(int argc, char **argv, struct config *config) return 0; } -int parse_ids(struct config *config) +static char *get_manufacturer(struct config *config, unsigned int manid) { - unsigned int ids_cnt = sizeof(database) / sizeof(struct ids_database); - unsigned int value; - char **ids; - char *type; + struct ids_database *db = config->bus == MMC ? mmc_database : sd_database; + unsigned int ids_cnt = ARRAY_SIZE(db); int i; for (i = 0; i < ids_cnt; i++) { - type = database[i].type; - - if (!strcmp(type, "mmc")) { - ids = config->mmc_ids; - } else if (!strcmp(type, "sd")) { - ids = config->sd_ids; - } else { - fprintf(stderr, - "MMC/SD id parse error, unknown type: '%s'.\n", - type); - return -1; - } - - value = database[i].id; - - if (value >= IDS_MAX) { - fprintf(stderr, - "MMC/SD id parse error, id out of range.\n"); - return -1; - } - - if (ids[value]) { - fprintf(stderr, - "Duplicate entries: type='%s', id='0x%1x'.\n", - type, value); - return -1; - } - - ids[value] = database[i].manufacturer; + if (db[i].id == manid) + return db[i].manufacturer; } - return 0; + return NULL; } /* MMC/SD file parsing functions */ @@ -538,6 +480,7 @@ void print_sd_cid(struct config *config, char *cid) unsigned int mdt_month; unsigned int mdt_year; unsigned int crc; + char *manufacturer = NULL; parse_bin(cid, "8u16a40a4u4u32u4r8u4u7u1r", &mid, &oid[0], &pnm[0], &prv_major, &prv_minor, &psn, @@ -546,12 +489,14 @@ void print_sd_cid(struct config *config, char *cid) oid[2] = '\0'; pnm[5] = '\0'; + manufacturer = get_manufacturer(config, mid); + if (config->verbose) { printf("======SD/CID======\n"); printf("\tMID: 0x%02x (", mid); - if (config->sd_ids[mid]) - printf("%s)\n", config->sd_ids[mid]); + if (manufacturer) + printf("%s)\n", manufacturer); else printf("Unlisted)\n"); @@ -564,9 +509,9 @@ void print_sd_cid(struct config *config, char *cid) 2000 + mdt_year, months[mdt_month]); printf("\tCRC: 0x%02x\n", crc); } else { - if (config->sd_ids[mid]) + if (manufacturer) printf("manufacturer: '%s' '%s'\n", - config->sd_ids[mid], oid); + manufacturer, oid); else printf("manufacturer: 'Unlisted' '%s'\n", oid); @@ -594,6 +539,7 @@ void print_mmc_cid(struct config *config, char *cid) unsigned int mdt_month; unsigned int mdt_year; unsigned int crc; + char *manufacturer = NULL; parse_bin(cid, "8u6r2u8u48a4u4u32u4u4u7u1r", &mid, &cbx, &oid, &pnm[0], &prv_major, &prv_minor, &psn, @@ -601,12 +547,14 @@ void print_mmc_cid(struct config *config, char *cid) pnm[6] = '\0'; + manufacturer = get_manufacturer(config, mid); + if (config->verbose) { printf("======MMC/CID======\n"); printf("\tMID: 0x%02x (", mid); - if (config->mmc_ids[mid]) - printf("%s)\n", config->mmc_ids[mid]); + if (manufacturer) + printf("%s)\n", manufacturer); else printf("Unlisted)\n"); @@ -635,9 +583,9 @@ void print_mmc_cid(struct config *config, char *cid) 1997 + mdt_year, months[mdt_month]); printf("\tCRC: 0x%02x\n", crc); } else { - if (config->mmc_ids[mid]) + if (manufacturer) printf("manufacturer: 0x%02x (%s) oid: 0x%01x\n", - mid, config->mmc_ids[mid], oid); + mid, manufacturer, oid); else printf("manufacturer: 0x%02x (Unlisted) oid: 0x%01x\n", mid, oid); @@ -2308,6 +2256,8 @@ int process_dir(struct config *config, enum REG_TYPE reg) goto err; } + config->bus = strcmp(type, "MMC") ? SD : MMC; + switch (reg) { case CID: cid = read_file("cid"); @@ -2369,45 +2319,19 @@ err: return ret; } -int lsmmc_main(struct config *config, int argc, char **argv) -{ - int ret; - - config->mmc_ids = calloc(IDS_MAX, sizeof(char *)); - config->sd_ids = calloc(IDS_MAX, sizeof(char *)); - if (!config->mmc_ids || !config->sd_ids) { - fprintf(stderr, "Could not allocate memory for lsmmc.\n"); - return -1; - } - - ret = parse_opts(argc, argv, config); - if (ret) - return ret; - - return parse_ids(config); -} - -void lsmmc_free(struct config *config) -{ - free(config->mmc_ids); - free(config->sd_ids); - free(config->dir); -} - static int do_read_reg(int argc, char **argv, enum REG_TYPE reg) { struct config cfg = {}; int ret; - ret = lsmmc_main(&cfg, argc, argv); + ret = parse_opts(argc, argv, &cfg); if (ret) - goto out; + return ret; if (cfg.dir) ret = process_dir(&cfg, reg); -out: - lsmmc_free(&cfg); + free(cfg.dir); return ret; From patchwork Tue Sep 26 10:00:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 726950 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B341BE7D273 for ; Tue, 26 Sep 2023 10:02:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234206AbjIZKCi (ORCPT ); Tue, 26 Sep 2023 06:02:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234337AbjIZKCf (ORCPT ); Tue, 26 Sep 2023 06:02:35 -0400 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66CDD97 for ; Tue, 26 Sep 2023 03:02:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1695722550; x=1727258550; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ua9aPNbtj0WT4TJ50xkgwq26uMkRGmH1em8NHPFYUSY=; b=BDSXxPfRPxrba0W6P3nIm+eJNh85XdCeTfNeYWPg9hVgD6UeEnAjY8ol iZL33euDNwqxnOZZORWwHksgo0Suq40dduBgAmyTMosLKglwNklrfXfTR eGZKExBgdhQ48EdOYqskzTFvhmit+3r+gNEGH0fEgnKwvoA7COF9cxa/A Rf7bkgK34mNrvimd8PW9R360V6AWNFCO9VSESLO0kQBVZOnYAbqKpdyVo XHQV6gTHW9kBu/T9NvuIit5pYx6mM3j5e/fdjTgMsllgETMGlzNtw0K9E Tn26iOOQ5wkrTAT/pBn0AyAHd9FSNDt9g4grF2XWeRiagJ1YixRfizvqv w==; X-CSE-ConnectionGUID: u9l6HuBdQO6dC+3VDScW8A== X-CSE-MsgGUID: dynjXNziQOynxhYh7c8pjg== X-IronPort-AV: E=Sophos;i="6.03,177,1694707200"; d="scan'208";a="244969605" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Sep 2023 18:02:29 +0800 IronPort-SDR: klNrGiCiOsHYY5dvpQnBg8he5ruFHI6Fu1CxE+21FoZlbwEeL0Ewx6GqlrXDXrv1A7uwzIjkaw D24pBuBdY4gSyE+xLsnUcDAoWF5s9o4ctdKnEBgegIvR4ndu6ccbx/tPPuv2kVYP8SBraIqIaf HpPDaBVUAhHgz7P4mBurmlGSoJcJ1CuA3IyWaxN8P3CeT1CCIDUBOR6e9H6QlDJV12JVFw8yEY xBR5JpznNkFsZtE0kma3AsOZx3HgAa+b7WtnrBA4eo8rzddbS9bBWqWyzV14ky/5grbptwoRMJ sUA= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 26 Sep 2023 02:14:57 -0700 IronPort-SDR: hQghx4aD5YEloXBhYCbbmUuEVku/DRzIMU68aKH+gvoTvMwLwIrIgEUgUK5S9C+14NCO1Vyf1d vQQdztKAB2s+fE1foeFoKBV4calHkn/djuFFZIUFBEJRMfgbNOIUKAbbqUP5Qw6seqcqgCX3g/ IYC1ePZrVOjPBse1a2hlLszVI/oTk8Yh33tgdhA4CooD91rXcdUssn+3PY8B4U/u+dp5ZGLIOJ RH7fmH3iXJ3xL4ofeTGYdeaAa7EopC81LnhSmWZcFYCHJpm1OC/enTT6r7IbQBHzOhFCJebZD8 QVg= WDCIronportException: Internal Received: from avri-office.ad.shared (HELO avri-office.sdcorp.global.sandisk.com) ([10.45.31.142]) by uls-op-cesaip02.wdc.com with ESMTP; 26 Sep 2023 03:02:29 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Avri Altman Subject: [PATCH 3/5] mmc-utils: lsmmc: Simplify interface processing functions Date: Tue, 26 Sep 2023 13:00:04 +0300 Message-Id: <20230926100006.1789276-4-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230926100006.1789276-1-avri.altman@wdc.com> References: <20230926100006.1789276-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Call those directly form process_dir() and remove the no longer needed print_info(). While at it remove the deprecated EXT_CSD handling. Signed-off-by: Avri Altman --- lsmmc.c | 70 ++++++++++++++++++++------------------------------------- 1 file changed, 24 insertions(+), 46 deletions(-) diff --git a/lsmmc.c b/lsmmc.c index 7e3165a..dae75b6 100644 --- a/lsmmc.c +++ b/lsmmc.c @@ -77,7 +77,6 @@ enum REG_TYPE { CID = 0, CSD, SCR, - EXT_CSD, }; struct ids_database { @@ -2210,29 +2209,10 @@ void print_sd_scr(struct config *config, char *scr) } } -/* MMC/SD interface processing functions */ -void print_info(struct config *config, char *type, - char *cid, char *csd, char *scr, char *ext_csd) -{ - printf("type: '%s'\n", type); - - if (!strcmp(type, "SD") && cid) - print_sd_cid(config, cid); - else if (!strcmp(type, "MMC") && cid) - print_mmc_cid(config, cid); - - if (!strcmp(type, "SD") && scr) - print_sd_scr(config, scr); - - if (!strcmp(type, "MMC") && csd) - print_mmc_csd(config, csd); - else if (!strcmp(type, "SD") && csd) - print_sd_csd(config, csd); -} - int process_dir(struct config *config, enum REG_TYPE reg) { - char *type = NULL, *cid = NULL, *csd = NULL, *scr = NULL, *ext_csd = NULL; + char *type = NULL; + char *reg_content = NULL; int ret = 0; if (chdir(config->dir) < 0) { @@ -2260,29 +2240,41 @@ int process_dir(struct config *config, enum REG_TYPE reg) switch (reg) { case CID: - cid = read_file("cid"); - if (!cid) { + reg_content = read_file("cid"); + if (!reg_content) { fprintf(stderr, "Could not read card identity in directory '%s'.\n", config->dir); ret = -1; goto err; } + + if (config->bus == SD) + print_sd_cid(config, reg_content); + else + print_mmc_cid(config, reg_content); + break; case CSD: - csd = read_file("csd"); - if (!csd) { + reg_content = read_file("csd"); + if (!reg_content) { fprintf(stderr, "Could not read card specific data in " "directory '%s'.\n", config->dir); ret = -1; goto err; } + + if (config->bus == SD) + print_sd_csd(config, reg_content); + else + print_mmc_csd(config, reg_content); + break; case SCR: if (!strcmp(type, "SD")) { - scr = read_file("scr"); - if (!scr) { + reg_content = read_file("scr"); + if (!reg_content) { fprintf(stderr, "Could not read SD card " "configuration in directory '%s'.\n", config->dir); @@ -2290,30 +2282,16 @@ int process_dir(struct config *config, enum REG_TYPE reg) goto err; } } - break; - case EXT_CSD: - if (!strcmp(type, "MMC")) { - ext_csd = read_file("ext_csd"); - if (!ext_csd) { - fprintf(stderr, "Could not read extra specific " - "data in directory '%s'.\n", - config->dir); - ret = -1; - goto err; - } - } + + print_sd_scr(config, reg_content); + break; default: goto err; } - print_info(config, type, cid, csd, scr, ext_csd); - err: - free(ext_csd); - free(scr); - free(csd); - free(cid); + free(reg_content); free(type); return ret; From patchwork Tue Sep 26 10:00:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 726620 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94A73E7D273 for ; Tue, 26 Sep 2023 10:02:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234325AbjIZKCv (ORCPT ); Tue, 26 Sep 2023 06:02:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234339AbjIZKCu (ORCPT ); Tue, 26 Sep 2023 06:02:50 -0400 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19D6510E for ; Tue, 26 Sep 2023 03:02:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1695722560; x=1727258560; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OKqgeNPdf0jmPEzpe52YzrZva60sZVSZQPSbUMY2sww=; b=BBH/eHn2bUn8blEZ1sWSLFzJfUfGZAMdHHg9RVTTS9fC3f3CW97LlOwd afFLntUEmaV3yQeL3wHmFsH6KLp6MMX3ZIOSx7mg8tYpot42KeeIJlA5L MjLy8YDiVB/0LBgAfhEOPJi0cd+P6C2VggH4OV6304yb/Qm81CEA/0Ehi jgRo7k7/5MVnKlgX1GEgfhQSSVebIUYsWjiPpI2QrBfDQHMFJttyAMNlq T1rFM2/a9ZDLwXV6pvfbi31ALb8hcR4g1mbWk8rD1foNs5uzZXQ+qEChM 2ez0A8+xvS6pqRH6CRp35VgutvQF6cVXiOR/ZPnsy6758IzF0cJUWeJZm A==; X-CSE-ConnectionGUID: CPN300eGQzyAVZt+dlMxEw== X-CSE-MsgGUID: XS4Lq7++RKCmFe/epgXxZw== X-IronPort-AV: E=Sophos;i="6.03,177,1694707200"; d="scan'208";a="249466762" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Sep 2023 18:02:39 +0800 IronPort-SDR: 9/fkC+Z126NeA+LiUBpVY7242DTSknt0oh3EJQ53cehPkI6iKzfHvmOV/E11WK+Qoxc0arVMo+ MquYBXux+UD2m8XkjBM6CYQ+itCZHuzviTxbJCB2JeoBwYxRiiwSg63PXVbp5xt8hTOf4HnMvg lYRCegV6hKNwFdiZZw7I0d45s6JlniPkdE+5rHRqCsvAWUDyRacIryRFkEh7We/0eNJRGt3Ndc FKJsCrCzuR639FJuSIey3FA7wc3WDfbB48QogTGU3NwdKZ3AB977BPwwaSy7Wp+bdXpHLxbrNo wg0= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 26 Sep 2023 02:15:07 -0700 IronPort-SDR: 415MGMdEm7KqN1VB2Ax48/+MTnaGhnY0AN4z1TmrGDc/kyUHswRY8uadq1N/7CiIl8eqc4wHNB ZLk5qXw1A44P32Ad6jZKor9uK01/4dN1+bYLEIweoJgQu9PL2M+1SdQTel+TWlXE9b3PYgDoZZ s/fdGrQUHbiDLgLBebdS/Qjir4+zbdxPSSgmllgrAw3LKYQIiw/QUKcgWyj32RnXCWy3J6ZW5t jLNE11/XSC1ivoAso+0k8bggCsGNjJg7AWwqBaic20T63NNHoFY9H0jB0gNrfGjb0KHXxbSF/i pe0= WDCIronportException: Internal Received: from avri-office.ad.shared (HELO avri-office.sdcorp.global.sandisk.com) ([10.45.31.142]) by uls-op-cesaip02.wdc.com with ESMTP; 26 Sep 2023 03:02:37 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Avri Altman Subject: [PATCH 4/5] mmc-utils: lsmmc: Disintegrade print_mmc_csd Date: Tue, 26 Sep 2023 13:00:05 +0300 Message-Id: <20230926100006.1789276-5-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230926100006.1789276-1-avri.altman@wdc.com> References: <20230926100006.1789276-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Make it more readable and manageable. No functional change. Signed-off-by: Avri Altman --- lsmmc.c | 1322 +++++++++++++++++++++++++++---------------------------- 1 file changed, 653 insertions(+), 669 deletions(-) diff --git a/lsmmc.c b/lsmmc.c index dae75b6..ef8fab1 100644 --- a/lsmmc.c +++ b/lsmmc.c @@ -1218,502 +1218,677 @@ void print_sd_csd(struct config *config, char *csd) } } -void print_mmc_csd(struct config *config, char *csd) +static void print_mmc_csd_structure(unsigned int csd_structure) { - unsigned int csd_structure; - unsigned int spec_vers; - unsigned int taac_timevalue; - unsigned int taac_timeunit; - unsigned int nsac; - unsigned int tran_speed_timevalue; - unsigned int tran_speed_transferrateunit; - unsigned int ccc; - unsigned int read_bl_len; - unsigned int read_bl_partial; - unsigned int write_blk_misalign; - unsigned int read_blk_misalign; - unsigned int dsr_imp; - unsigned int c_size; - unsigned int vdd_r_curr_min; - unsigned int vdd_r_curr_max; - unsigned int vdd_w_curr_min; - unsigned int vdd_w_curr_max; - unsigned int c_size_mult; - unsigned int erase_grp_size; - unsigned int erase_grp_mult; - unsigned int wp_grp_size; - unsigned int wp_grp_enable; - unsigned int default_ecc; - unsigned int r2w_factor; - unsigned int write_bl_len; - unsigned int write_bl_partial; - unsigned int content_prot_app; - unsigned int file_format_grp; - unsigned int copy; - unsigned int perm_write_protect; - unsigned int tmp_write_protect; - unsigned int file_format; - unsigned int ecc; - unsigned int crc; - unsigned int taac; - unsigned int tran_speed; + printf("\tCSD_STRUCTURE: 0x%01x (", csd_structure); + switch (csd_structure) { + case 0x0: + printf("v1.0)\n"); + break; + case 0x1: + printf("v1.1)\n"); + break; + case 0x2: + printf("v1.2)\n"); + break; + case 0x3: + printf("version in ext_csd)\n"); + break; + } +} - parse_bin(csd, "2u4u2r1r4u3u8u1r4u3u12u4u1u1u1u1u2r12u3u3u3u3u3u" - "5u5u5u1u2u3u4u1u4r1u1u1u1u1u2u2u7u1r", - &csd_structure, &spec_vers, &taac_timevalue, - &taac_timeunit, &nsac, &tran_speed_timevalue, - &tran_speed_transferrateunit, &ccc, &read_bl_len, - &read_bl_partial, &write_blk_misalign, - &read_blk_misalign, &dsr_imp, &c_size, - &vdd_r_curr_min, &vdd_r_curr_max, - &vdd_w_curr_min, &vdd_w_curr_max, &c_size_mult, - &erase_grp_size, &erase_grp_mult, &wp_grp_size, - &wp_grp_enable, &default_ecc, &r2w_factor, - &write_bl_len, &write_bl_partial, &content_prot_app, - &file_format_grp, ©, &perm_write_protect, - &tmp_write_protect, &file_format, &ecc, &crc); +static void print_mmc_csd_spec_ver(unsigned int spec_vers) +{ + printf("\tSPEC_VERS: 0x%01x (", spec_vers); + switch (spec_vers) { + case 0x0: + printf("v1.0-v1.2)\n"); + break; + case 0x1: + printf("v1.4)\n"); + break; + case 0x2: + printf("v2.0-v2.2)\n"); + break; + case 0x3: + printf("v3.1-v3.31)\n"); + break; + case 0x4: + printf("v4.0-v4.3)\n"); + break; + default: + printf("reserved)\n"); + break; + } +} - taac = taac_timevalue << 3 | taac_timeunit; - tran_speed = tran_speed_timevalue << 3 | tran_speed_transferrateunit; +static void +print_mmc_csd_taac(unsigned int taac_timevalue, unsigned int taac_timeunit) +{ + float value; + unsigned int taac = taac_timevalue << 3 | taac_timeunit; - if (config->verbose) { - float value; - int mult; - int blocknr; - int block_len; - unsigned long long blocks = 0; - int block_size = 0; - unsigned long long memory_capacity; + printf("\tTAAC: 0x%02x (", taac); + switch (taac_timevalue) { + case 0x0: + value = 0.0f; + break; + case 0x1: + value = 1.0f; + break; + case 0x2: + value = 1.2f; + break; + case 0x3: + value = 1.3f; + break; + case 0x4: + value = 1.5f; + break; + case 0x5: + value = 2.0f; + break; + case 0x6: + value = 2.5f; + break; + case 0x7: + value = 3.0f; + break; + case 0x8: + value = 3.5f; + break; + case 0x9: + value = 4.0f; + break; + case 0xa: + value = 4.5f; + break; + case 0xb: + value = 5.0f; + break; + case 0xc: + value = 5.5f; + break; + case 0xd: + value = 6.0f; + break; + case 0xe: + value = 7.0f; + break; + case 0xf: + value = 8.0f; + break; + default: + value = 0.0f; + break; + } - printf("======MMC/CSD======\n"); + switch (taac_timeunit) { + case 0x0: + printf("%.2fns)\n", value * 1.0f); + break; + case 0x1: + printf("%.2fns)\n", value * 10.0f); + break; + case 0x2: + printf("%.2fns)\n", value * 100.0f); + break; + case 0x3: + printf("%.2fus)\n", value * 1.0f); + break; + case 0x4: + printf("%.2fus)\n", value * 10.0f); + break; + case 0x5: + printf("%.2fus)\n", value * 100.0f); + break; + case 0x6: + printf("%.2fms)\n", value * 1.0f); + break; + case 0x7: + printf("%.2fms)\n", value * 10.0f); + break; + } +} - printf("\tCSD_STRUCTURE: 0x%01x (", csd_structure); - switch (csd_structure) { - case 0x0: - printf("v1.0)\n"); - break; - case 0x1: - printf("v1.1)\n"); - break; - case 0x2: - printf("v1.2)\n"); - break; - case 0x3: - printf("version in ext_csd)\n"); - break; - } +static void print_mmc_csd_nsac(unsigned int nsac, unsigned int tran_speed_timevalue, + unsigned int tran_speed_transferrateunit) +{ + float value; + unsigned int tran_speed = tran_speed_timevalue << 3 | tran_speed_transferrateunit; + + printf("\tNSAC: %u clocks\n", nsac); + printf("\tTRAN_SPEED: 0x%02x (", tran_speed); + switch (tran_speed_timevalue) { + case 0x0: + value = 0.0f; + break; + case 0x1: + value = 1.0f; + break; + case 0x2: + value = 1.2f; + break; + case 0x3: + value = 1.3f; + break; + case 0x4: + value = 1.5f; + break; + case 0x5: + value = 2.0f; + break; + case 0x6: + value = 2.6f; + break; + case 0x7: + value = 3.0f; + break; + case 0x8: + value = 3.5f; + break; + case 0x9: + value = 4.0f; + break; + case 0xa: + value = 4.5f; + break; + case 0xb: + value = 5.2f; + break; + case 0xc: + value = 5.5f; + break; + case 0xd: + value = 6.0f; + break; + case 0xe: + value = 7.0f; + break; + case 0xf: + value = 8.0f; + break; + default: + value = 0.0f; + break; + } - printf("\tSPEC_VERS: 0x%01x (", spec_vers); - switch (spec_vers) { - case 0x0: - printf("v1.0-v1.2)\n"); - break; - case 0x1: - printf("v1.4)\n"); - break; - case 0x2: - printf("v2.0-v2.2)\n"); - break; - case 0x3: - printf("v3.1-v3.31)\n"); - break; - case 0x4: - printf("v4.0-v4.3)\n"); - break; - default: - printf("reserved)\n"); - break; - } + switch (tran_speed_transferrateunit) { + case 0x0: + printf("%.2fKHz/s)\n", value * 100.0f); + break; + case 0x1: + printf("%.2fMHz/s)\n", value * 1.0f); + break; + case 0x2: + printf("%.2fMHz/s)\n", value * 10.0f); + break; + case 0x3: + printf("%.2fMHz/s)\n", value * 100.0f); + break; + default: + printf("reserved)\n"); + break; + } +} - printf("\tTAAC: 0x%02x (", taac); - switch (taac_timevalue) { - case 0x0: - value = 0.0f; - break; - case 0x1: - value = 1.0f; - break; - case 0x2: - value = 1.2f; - break; - case 0x3: - value = 1.3f; - break; - case 0x4: - value = 1.5f; - break; - case 0x5: - value = 2.0f; - break; - case 0x6: - value = 2.5f; - break; - case 0x7: - value = 3.0f; - break; - case 0x8: - value = 3.5f; - break; - case 0x9: - value = 4.0f; - break; - case 0xa: - value = 4.5f; - break; - case 0xb: - value = 5.0f; - break; - case 0xc: - value = 5.5f; - break; - case 0xd: - value = 6.0f; - break; - case 0xe: - value = 7.0f; - break; - case 0xf: - value = 8.0f; - break; - default: - value = 0.0f; - break; - } +static void print_mmc_csd_ccc(unsigned int ccc) +{ + printf("\tCCC: 0x%03x (class: ", ccc); + if (ccc & 0x800) + printf("11, "); + if (ccc & 0x400) + printf("10, "); + if (ccc & 0x200) + printf("9, "); + if (ccc & 0x100) + printf("8, "); + if (ccc & 0x080) + printf("7, "); + if (ccc & 0x040) + printf("6, "); + if (ccc & 0x020) + printf("5, "); + if (ccc & 0x010) + printf("4, "); + if (ccc & 0x008) + printf("3, "); + if (ccc & 0x004) + printf("2, "); + if (ccc & 0x002) + printf("1, "); + if (ccc & 0x001) + printf("0, "); + printf(" )\n"); +} - switch (taac_timeunit) { - case 0x0: - printf("%.2fns)\n", value * 1.0f); - break; - case 0x1: - printf("%.2fns)\n", value * 10.0f); - break; - case 0x2: - printf("%.2fns)\n", value * 100.0f); - break; - case 0x3: - printf("%.2fus)\n", value * 1.0f); - break; - case 0x4: - printf("%.2fus)\n", value * 10.0f); - break; - case 0x5: - printf("%.2fus)\n", value * 100.0f); - break; - case 0x6: - printf("%.2fms)\n", value * 1.0f); - break; - case 0x7: - printf("%.2fms)\n", value * 10.0f); - break; - } +static void print_mmc_csd_read_bl_len(unsigned int read_bl_len) +{ + printf("\tREAD_BL_LEN: 0x%01x (", read_bl_len); + switch (read_bl_len) { + case 0x0: + printf("1 byte)\n"); + break; + case 0x1: + printf("2 byte)\n"); + break; + case 0x2: + printf("4 byte)\n"); + break; + case 0x3: + printf("8 byte)\n"); + break; + case 0x4: + printf("16 byte)\n"); + break; + case 0x5: + printf("32 byte)\n"); + break; + case 0x6: + printf("64 byte)\n"); + break; + case 0x7: + printf("128 byte)\n"); + break; + case 0x8: + printf("256 byte)\n"); + break; + case 0x9: + printf("512 bytes)\n"); + break; + case 0xa: + printf("1024 bytes)\n"); + break; + case 0xb: + printf("2048 bytes)\n"); + break; + case 0xc: + printf("4096 bytes)\n"); + break; + case 0xd: + printf("8192 bytes)\n"); + break; + case 0xe: + printf("16K bytes)\n"); + break; + default: + printf("reserved bytes)\n"); + break; + } +} - printf("\tNSAC: %u clocks\n", nsac); - printf("\tTRAN_SPEED: 0x%02x (", tran_speed); - switch (tran_speed_timevalue) { - case 0x0: - value = 0.0f; - break; - case 0x1: - value = 1.0f; - break; - case 0x2: - value = 1.2f; - break; - case 0x3: - value = 1.3f; - break; - case 0x4: - value = 1.5f; - break; - case 0x5: - value = 2.0f; - break; - case 0x6: - value = 2.6f; - break; - case 0x7: - value = 3.0f; - break; - case 0x8: - value = 3.5f; - break; - case 0x9: - value = 4.0f; - break; - case 0xa: - value = 4.5f; - break; - case 0xb: - value = 5.2f; - break; - case 0xc: - value = 5.5f; - break; - case 0xd: - value = 6.0f; - break; - case 0xe: - value = 7.0f; - break; - case 0xf: - value = 8.0f; - break; - default: - value = 0.0f; - break; - } +static void print_mmc_csd_read_bl_partial(unsigned int read_bl_partial) +{ + printf("\tREAD_BL_PARTIAL: 0x%01x (", read_bl_partial); + switch (read_bl_partial) { + case 0x0: + printf("only 512 byte and READ_BL_LEN block size)\n"); + break; + case 0x1: + printf("less than READ_BL_LEN block size can be used)\n"); + break; + } +} - switch (tran_speed_transferrateunit) { - case 0x0: - printf("%.2fKHz/s)\n", value * 100.0f); - break; - case 0x1: - printf("%.2fMHz/s)\n", value * 1.0f); - break; - case 0x2: - printf("%.2fMHz/s)\n", value * 10.0f); - break; - case 0x3: - printf("%.2fMHz/s)\n", value * 100.0f); - break; - default: - printf("reserved)\n"); - break; - } +static void print_mmc_csd_write_blk_misalign(unsigned int write_blk_misalign) +{ + printf("\tWRITE_BLK_MISALIGN: 0x%01x (", write_blk_misalign); + switch (write_blk_misalign) { + case 0x0: + printf("writes across block boundaries are invalid)\n"); + break; + case 0x1: + printf("writes across block boundaries are allowed)\n"); + break; + } +} - printf("\tCCC: 0x%03x (class: ", ccc); - if (ccc & 0x800) - printf("11, "); - if (ccc & 0x400) - printf("10, "); - if (ccc & 0x200) - printf("9, "); - if (ccc & 0x100) - printf("8, "); - if (ccc & 0x080) - printf("7, "); - if (ccc & 0x040) - printf("6, "); - if (ccc & 0x020) - printf("5, "); - if (ccc & 0x010) - printf("4, "); - if (ccc & 0x008) - printf("3, "); - if (ccc & 0x004) - printf("2, "); - if (ccc & 0x002) - printf("1, "); - if (ccc & 0x001) - printf("0, "); - printf(" )\n"); +static void print_mmc_csd_read_blk_misalign(unsigned int read_blk_misalign) +{ + printf("\tREAD_BLK_MISALIGN: 0x%01x (", read_blk_misalign); + switch (read_blk_misalign) { + case 0x0: + printf("reads across block boundaries are invalid)\n"); + break; + case 0x1: + printf("reads across block boundaries are allowed)\n"); + break; + } +} - printf("\tREAD_BL_LEN: 0x%01x (", read_bl_len); - switch (read_bl_len) { - case 0x0: - printf("1 byte)\n"); - break; - case 0x1: - printf("2 byte)\n"); - break; - case 0x2: - printf("4 byte)\n"); - break; - case 0x3: - printf("8 byte)\n"); - break; - case 0x4: - printf("16 byte)\n"); - break; - case 0x5: - printf("32 byte)\n"); - break; - case 0x6: - printf("64 byte)\n"); - break; - case 0x7: - printf("128 byte)\n"); - break; - case 0x8: - printf("256 byte)\n"); - break; - case 0x9: - printf("512 bytes)\n"); - break; - case 0xa: - printf("1024 bytes)\n"); - break; - case 0xb: - printf("2048 bytes)\n"); - break; - case 0xc: - printf("4096 bytes)\n"); - break; - case 0xd: - printf("8192 bytes)\n"); - break; - case 0xe: - printf("16K bytes)\n"); - break; - default: - printf("reserved bytes)\n"); - break; - } +static void print_mmc_csd_dsr_imp(unsigned int dsr_imp) +{ + printf("\tDSR_IMP: 0x%01x (", dsr_imp); + switch (dsr_imp) { + case 0x0: + printf("configurable driver stage not available)\n"); + break; + case 0x1: + printf("configurable driver state available)\n"); + break; + } +} - printf("\tREAD_BL_PARTIAL: 0x%01x (", read_bl_partial); - switch (read_bl_partial) { - case 0x0: - printf("only 512 byte and READ_BL_LEN block size)\n"); - break; - case 0x1: - printf("less than READ_BL_LEN block size can be used)\n"); - break; - } +static void print_mmc_csd_vdd(unsigned int vdd_r_curr_min, unsigned int vdd_r_curr_max, + unsigned int vdd_w_curr_min, unsigned int vdd_w_curr_max) +{ + printf("\tVDD_R_CURR_MIN: 0x%01x (", vdd_r_curr_min); + switch (vdd_r_curr_min) { + case 0x0: + printf("0.5mA)\n"); + break; + case 0x1: + printf("1mA)\n"); + break; + case 0x2: + printf("5mA)\n"); + break; + case 0x3: + printf("10mA)\n"); + break; + case 0x4: + printf("25mA)\n"); + break; + case 0x5: + printf("35mA)\n"); + break; + case 0x6: + printf("60mA)\n"); + break; + case 0x7: + printf("100mA)\n"); + break; + } - printf("\tWRITE_BLK_MISALIGN: 0x%01x (", write_blk_misalign); - switch (write_blk_misalign) { - case 0x0: - printf("writes across block boundaries are invalid)\n"); - break; - case 0x1: - printf("writes across block boundaries are allowed)\n"); - break; - } + printf("\tVDD_R_CURR_MAX: 0x%01x (", vdd_r_curr_max); + switch (vdd_r_curr_max) { + case 0x0: + printf("1mA)\n"); + break; + case 0x1: + printf("5mA)\n"); + break; + case 0x2: + printf("10mA)\n"); + break; + case 0x3: + printf("25mA)\n"); + break; + case 0x4: + printf("35mA)\n"); + break; + case 0x5: + printf("45mA)\n"); + break; + case 0x6: + printf("80mA)\n"); + break; + case 0x7: + printf("200mA)\n"); + break; + } - printf("\tREAD_BLK_MISALIGN: 0x%01x (", read_blk_misalign); - switch (read_blk_misalign) { - case 0x0: - printf("reads across block boundaries are invalid)\n"); - break; - case 0x1: - printf("reads across block boundaries are allowed)\n"); - break; - } + printf("\tVDD_W_CURR_MIN: 0x%01x (", vdd_w_curr_min); + switch (vdd_w_curr_min) { + case 0x0: + printf("0.5mA)\n"); + break; + case 0x1: + printf("1mA)\n"); + break; + case 0x2: + printf("5mA)\n"); + break; + case 0x3: + printf("10mA)\n"); + break; + case 0x4: + printf("25mA)\n"); + break; + case 0x5: + printf("35mA)\n"); + break; + case 0x6: + printf("60mA)\n"); + break; + case 0x7: + printf("100mA)\n"); + break; + } - printf("\tDSR_IMP: 0x%01x (", dsr_imp); - switch (dsr_imp) { - case 0x0: - printf("configurable driver stage not available)\n"); - break; - case 0x1: - printf("configurable driver state available)\n"); - break; - } + printf("\tVDD_W_CURR_MAX: 0x%01x (", vdd_w_curr_max); + switch (vdd_w_curr_max) { + case 0x0: + printf("1mA)\n"); + break; + case 0x1: + printf("5mA)\n"); + break; + case 0x2: + printf("10mA)\n"); + break; + case 0x3: + printf("25mA)\n"); + break; + case 0x4: + printf("35mA)\n"); + break; + case 0x5: + printf("45mA)\n"); + break; + case 0x6: + printf("80mA)\n"); + break; + case 0x7: + printf("200mA)\n"); + break; + } +} + +static void print_mmc_csd_default_ecc(unsigned int default_ecc) +{ + printf("\tDEFAULT_ECC: 0x%01x (", default_ecc); + switch (default_ecc) { + case 0: + printf("none)\n"); + break; + case 1: + printf("BCH)\n"); + break; + default: + printf("reserved)\n"); + break; + } +} + +static void print_mmc_csd_write_bl_len(unsigned int write_bl_len) +{ + printf("\tWRITE_BL_LEN: 0x%01x (", write_bl_len); + switch (write_bl_len) { + case 0x0: + printf("1 byte)\n"); + break; + case 0x1: + printf("2 byte)\n"); + break; + case 0x2: + printf("4 byte)\n"); + break; + case 0x3: + printf("8 byte)\n"); + break; + case 0x4: + printf("16 byte)\n"); + break; + case 0x5: + printf("32 byte)\n"); + break; + case 0x6: + printf("64 byte)\n"); + break; + case 0x7: + printf("128 byte)\n"); + break; + case 0x8: + printf("256 byte)\n"); + break; + case 0x9: + printf("512 bytes)\n"); + break; + case 0xa: + printf("1024 bytes)\n"); + break; + case 0xb: + printf("2048 bytes)\n"); + break; + case 0xc: + printf("4096 bytes)\n"); + break; + case 0xd: + printf("8192 bytes)\n"); + break; + case 0xe: + printf("16K bytes)\n"); + break; + default: + printf("reserved bytes)\n"); + break; + } +} + +static void print_mmc_csd_write_bl_partial(unsigned int write_bl_partial) +{ + printf("\tWRITE_BL_PARTIAL: 0x%01x (", write_bl_partial); + switch (write_bl_partial) { + case 0x0: + printf("only 512 byte and WRITE_BL_LEN block size)\n"); + break; + case 0x1: + printf("less than WRITE_BL_LEN block size can be used)\n"); + break; + } +} - printf("\tC_SIZE: 0x%03x\n", c_size); - printf("\tVDD_R_CURR_MIN: 0x%01x (", vdd_r_curr_min); - switch (vdd_r_curr_min) { - case 0x0: - printf("0.5mA)\n"); - break; - case 0x1: - printf("1mA)\n"); - break; - case 0x2: - printf("5mA)\n"); - break; - case 0x3: - printf("10mA)\n"); - break; - case 0x4: - printf("25mA)\n"); - break; - case 0x5: - printf("35mA)\n"); - break; - case 0x6: - printf("60mA)\n"); - break; - case 0x7: - printf("100mA)\n"); - break; - } +static void print_mmc_csd_file_format(unsigned int file_format, unsigned int file_format_grp) +{ + printf("\tFILE_FORMAT: 0x%01x (", file_format); + if (file_format != 0) + printf("Warn: Invalid FILE_FORMAT\n"); - printf("\tVDD_R_CURR_MAX: 0x%01x (", vdd_r_curr_max); - switch (vdd_r_curr_max) { - case 0x0: - printf("1mA)\n"); - break; - case 0x1: - printf("5mA)\n"); - break; - case 0x2: - printf("10mA)\n"); - break; - case 0x3: - printf("25mA)\n"); - break; - case 0x4: - printf("35mA)\n"); + if (file_format_grp == 1) { + printf("reserved)\n"); + } else { + switch (file_format) { + case 0: + printf("partition table)\n"); break; - case 0x5: - printf("45mA)\n"); + case 1: + printf("no partition table)\n"); break; - case 0x6: - printf("80mA)\n"); + case 2: + printf("Universal File Format)\n"); break; - case 0x7: - printf("200mA)\n"); + case 3: + printf("Others/unknown)\n"); break; } + } +} - printf("\tVDD_W_CURR_MIN: 0x%01x (", vdd_w_curr_min); - switch (vdd_w_curr_min) { - case 0x0: - printf("0.5mA)\n"); - break; - case 0x1: - printf("1mA)\n"); - break; - case 0x2: - printf("5mA)\n"); - break; - case 0x3: - printf("10mA)\n"); - break; - case 0x4: - printf("25mA)\n"); - break; - case 0x5: - printf("35mA)\n"); - break; - case 0x6: - printf("60mA)\n"); - break; - case 0x7: - printf("100mA)\n"); - break; - } +static void print_mmc_csd_ecc(unsigned int ecc) +{ + printf("\tECC: 0x%01x (", ecc); + switch (ecc) { + case 0: + printf("none)\n"); + break; + case 1: + printf("BCH(542,512))\n"); + break; + default: + printf("reserved)\n"); + break; + } +} - printf("\tVDD_W_CURR_MAX: 0x%01x (", vdd_w_curr_max); - switch (vdd_w_curr_max) { - case 0x0: - printf("1mA)\n"); - break; - case 0x1: - printf("5mA)\n"); - break; - case 0x2: - printf("10mA)\n"); - break; - case 0x3: - printf("25mA)\n"); - break; - case 0x4: - printf("35mA)\n"); - break; - case 0x5: - printf("45mA)\n"); - break; - case 0x6: - printf("80mA)\n"); - break; - case 0x7: - printf("200mA)\n"); - break; - } +static void print_mmc_csd_capacity(unsigned int c_size, unsigned int c_size_mult, + unsigned int read_bl_len) +{ + int mult = 1 << (c_size_mult + 2); + unsigned long long blocknr = (c_size + 1) * mult; + int block_len = 1 << read_bl_len; + unsigned long long memory_capacity; + + printf("\tC_SIZE: 0x%03x\n", c_size); + printf("\tC_SIZE_MULT: 0x%01x\n", c_size_mult); + + memory_capacity = blocknr * block_len; + + printf("\tCAPACITY: "); + if (memory_capacity / (1024ull * 1024ull * 1024ull) > 0) + printf("%.2fGbyte", memory_capacity / (1024.0 * 1024.0 * 1024.0)); + else if (memory_capacity / (1024ull * 1024ull) > 0) + printf("%.2fMbyte", memory_capacity / (1024.0 * 1024.0)); + else if (memory_capacity / (1024ull) > 0) + printf("%.2fKbyte", memory_capacity / (1024.0)); + else + printf("%.2fbyte", memory_capacity * 1.0); + + printf(" (%llu bytes, %llu sectors, %d bytes each)\n", memory_capacity, blocknr, block_len); +} + +static void print_mmc_csd(struct config *config, char *csd) +{ + unsigned int csd_structure, spec_vers, taac_timevalue, taac_timeunit, nsac; + unsigned int tran_speed_timevalue, tran_speed_transferrateunit, ccc, read_bl_len; + unsigned int read_bl_partial, write_blk_misalign, read_blk_misalign, dsr_imp; + unsigned int c_size, vdd_r_curr_min, vdd_r_curr_max, vdd_w_curr_min, vdd_w_curr_max; + unsigned int c_size_mult, erase_grp_size, erase_grp_mult, wp_grp_size, wp_grp_enable; + unsigned int default_ecc, r2w_factor, write_bl_len, write_bl_partial, content_prot_app; + unsigned int file_format_grp, copy, perm_write_protect, tmp_write_protect, file_format; + unsigned int ecc, crc; + + parse_bin(csd, "2u4u2r1r4u3u8u1r4u3u12u4u1u1u1u1u2r12u3u3u3u3u3u" + "5u5u5u1u2u3u4u1u4r1u1u1u1u1u2u2u7u1r", + &csd_structure, &spec_vers, &taac_timevalue, + &taac_timeunit, &nsac, &tran_speed_timevalue, + &tran_speed_transferrateunit, &ccc, &read_bl_len, + &read_bl_partial, &write_blk_misalign, + &read_blk_misalign, &dsr_imp, &c_size, + &vdd_r_curr_min, &vdd_r_curr_max, + &vdd_w_curr_min, &vdd_w_curr_max, &c_size_mult, + &erase_grp_size, &erase_grp_mult, &wp_grp_size, + &wp_grp_enable, &default_ecc, &r2w_factor, + &write_bl_len, &write_bl_partial, &content_prot_app, + &file_format_grp, ©, &perm_write_protect, + &tmp_write_protect, &file_format, &ecc, &crc); + + if (config->verbose) { + + printf("======MMC/CSD======\n"); + + print_mmc_csd_structure(csd_structure); + + print_mmc_csd_spec_ver(spec_vers); + + print_mmc_csd_taac(taac_timevalue, taac_timeunit); + + print_mmc_csd_nsac(nsac, tran_speed_timevalue, tran_speed_transferrateunit); + + print_mmc_csd_ccc(ccc); + + print_mmc_csd_read_bl_len(read_bl_len); + + print_mmc_csd_read_bl_partial(read_bl_partial); + + print_mmc_csd_write_blk_misalign(write_blk_misalign); + + print_mmc_csd_read_blk_misalign(read_blk_misalign); + + print_mmc_csd_dsr_imp(dsr_imp); + + print_mmc_csd_vdd(vdd_r_curr_min, vdd_r_curr_max, vdd_w_curr_min, vdd_w_curr_max); - printf("\tC_SIZE_MULT: 0x%01x\n", c_size_mult); printf("\tERASE_GRP_SIZE: 0x%02x\n", erase_grp_size); printf("\tERASE_GRP_MULT: 0x%02x (%u write blocks/erase group)\n", erase_grp_mult, (erase_grp_size + 1) * @@ -1722,83 +1897,14 @@ void print_mmc_csd(struct config *config, char *csd) wp_grp_size, wp_grp_size + 1); printf("\tWP_GRP_ENABLE: 0x%01x\n", wp_grp_enable); - printf("\tDEFAULT_ECC: 0x%01x (", default_ecc); - switch (default_ecc) { - case 0: - printf("none)\n"); - break; - case 1: - printf("BCH)\n"); - break; - default: - printf("reserved)\n"); - break; - } + print_mmc_csd_default_ecc(default_ecc); printf("\tR2W_FACTOR: 0x%01x (Write %u times read)\n", r2w_factor, r2w_factor); - printf("\tWRITE_BL_LEN: 0x%01x (", write_bl_len); - switch (write_bl_len) { - case 0x0: - printf("1 byte)\n"); - break; - case 0x1: - printf("2 byte)\n"); - break; - case 0x2: - printf("4 byte)\n"); - break; - case 0x3: - printf("8 byte)\n"); - break; - case 0x4: - printf("16 byte)\n"); - break; - case 0x5: - printf("32 byte)\n"); - break; - case 0x6: - printf("64 byte)\n"); - break; - case 0x7: - printf("128 byte)\n"); - break; - case 0x8: - printf("256 byte)\n"); - break; - case 0x9: - printf("512 bytes)\n"); - break; - case 0xa: - printf("1024 bytes)\n"); - break; - case 0xb: - printf("2048 bytes)\n"); - break; - case 0xc: - printf("4096 bytes)\n"); - break; - case 0xd: - printf("8192 bytes)\n"); - break; - case 0xe: - printf("16K bytes)\n"); - break; - default: - printf("reserved bytes)\n"); - break; - } + print_mmc_csd_write_bl_len(write_bl_len); - printf("\tWRITE_BL_PARTIAL: 0x%01x (", write_bl_partial); - switch (write_bl_partial) { - case 0x0: - printf("only 512 byte and WRITE_BL_LEN block size)\n"); - break; - case 0x1: - printf("less than WRITE_BL_LEN block size can be used)\n"); - break; - } + print_mmc_csd_write_bl_partial(write_bl_partial); printf("\tCONTENT_PROT_APP: 0x%01x\n", content_prot_app); printf("\tFILE_FORMAT_GRP: 0x%01x\n", file_format_grp); @@ -1808,142 +1914,20 @@ void print_mmc_csd(struct config *config, char *csd) printf("\tCOPY: 0x%01x\n", copy); printf("\tPERM_WRITE_PROTECT: 0x%01x\n", perm_write_protect); printf("\tTMP_WRITE_PROTECT: 0x%01x\n", tmp_write_protect); - printf("\tFILE_FORMAT: 0x%01x (", file_format); - if (file_format != 0) - printf("Warn: Invalid FILE_FORMAT\n"); - if (file_format_grp == 1) { - printf("reserved)\n"); - } else { - switch (file_format) { - case 0: - printf("partition table)\n"); - break; - case 1: - printf("no partition table)\n"); - break; - case 2: - printf("Universal File Format)\n"); - break; - case 3: - printf("Others/unknown)\n"); - break; - } - } + print_mmc_csd_file_format(file_format, file_format_grp); - printf("\tECC: 0x%01x (", ecc); - switch (ecc) { - case 0: - printf("none)\n"); - break; - case 1: - printf("BCH(542,512))\n"); - break; - default: - printf("reserved)\n"); - break; - } + print_mmc_csd_ecc(ecc); printf("\tCRC: 0x%01x\n", crc); - mult = 1 << (c_size_mult + 2); - blocknr = (c_size + 1) * mult; - block_len = 1 << read_bl_len; - blocks = blocknr; - block_size = block_len; - - memory_capacity = blocks * block_size; - - printf("\tCAPACITY: "); - if (memory_capacity / (1024ull * 1024ull * 1024ull) > 0) - printf("%.2fGbyte", - memory_capacity / (1024.0 * 1024.0 * 1024.0)); - else if (memory_capacity / (1024ull * 1024ull) > 0) - printf("%.2fMbyte", memory_capacity / (1024.0 * 1024.0)); - else if (memory_capacity / (1024ull) > 0) - printf("%.2fKbyte", memory_capacity / (1024.0)); - else - printf("%.2fbyte", memory_capacity * 1.0); - - printf(" (%llu bytes, %llu sectors, %d bytes each)\n", - memory_capacity, blocks, block_size); + print_mmc_csd_capacity(c_size, c_size_mult, read_bl_len); } else { - int mult; - int blocknr; - int block_len; - unsigned long long blocks = 0; - int block_size = 0; - unsigned long long memory_capacity; - - printf("version: "); - switch (spec_vers) { - case 0x0: - printf("MMC v1.0-v1.2\n"); - break; - case 0x1: - printf("MMC v1.4\n"); - break; - case 0x2: - printf("MMC v2.0-v2.2\n"); - break; - case 0x3: - printf("MMC v3.1-v3.31\n"); - break; - case 0x4: - printf("MMC v4.0-v4.3\n"); - break; - default: - printf("reserved\n"); - break; - } - - printf("card classes: "); - if (ccc & 0x800) - printf("11, "); - if (ccc & 0x400) - printf("10, "); - if (ccc & 0x200) - printf("9, "); - if (ccc & 0x100) - printf("8, "); - if (ccc & 0x080) - printf("7, "); - if (ccc & 0x040) - printf("6, "); - if (ccc & 0x020) - printf("5, "); - if (ccc & 0x010) - printf("4, "); - if (ccc & 0x008) - printf("3, "); - if (ccc & 0x004) - printf("2, "); - if (ccc & 0x002) - printf("1, "); - if (ccc & 0x001) - printf("0, "); - printf("\b\b\n"); + print_mmc_csd_spec_ver(spec_vers); - mult = 1 << (c_size_mult + 2); - blocknr = (c_size + 1) * mult; - block_len = 1 << read_bl_len; - blocks = blocknr; - block_size = block_len; - - memory_capacity = blocks * block_size; + print_mmc_csd_ccc(ccc); - printf("capacity: "); - if (memory_capacity / (1024ull * 1024ull * 1024ull) > 0) - printf("%.2fGbyte", - memory_capacity / (1024.0 * 1024.0 * 1024.0)); - else if (memory_capacity / (1024ull * 1024ull) > 0) - printf("%.2fMbyte", memory_capacity / (1024.0 * 1024.0)); - else if (memory_capacity / (1024ull) > 0) - printf("%.2fKbyte", memory_capacity / (1024.0)); - else - printf("%.2fbyte", memory_capacity * 1.0); - printf(" (%llu bytes, %llu sectors, %d bytes each)\n", - memory_capacity, blocks, block_size); + print_mmc_csd_capacity(c_size, c_size_mult, read_bl_len); } } From patchwork Tue Sep 26 10:00:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 726949 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86BDFE7D271 for ; Tue, 26 Sep 2023 10:02:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234095AbjIZKC7 (ORCPT ); Tue, 26 Sep 2023 06:02:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234342AbjIZKC6 (ORCPT ); Tue, 26 Sep 2023 06:02:58 -0400 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77383136 for ; Tue, 26 Sep 2023 03:02:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1695722570; x=1727258570; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LcqSpfHBQ0Qsu49muu5nz5nVW+RjSHg1/kEmKm33Pp4=; b=IYXlentoB8v6wmCVee7py7ixSVcC78t+fJ4QLh8vucyg4Nd81mK1/Zq1 A7Q6xXdr77BZDf5xCe2fVKC5A9GfB39Ez5W+aUTiATMnarfKPsabcGqr0 fEz2UyddT640yBBJ3xgATdhuCdsFmIt6F2RzTo1iq8kSI5TgfAVc9gL+W h6IEFjO9vKVghCj+VBeUTWwdIDgPTYS9X3qnhIS/5VW2bERipaiZSDAqp 5aCJH4d3c3n66s1/GnS+zt3AHMosuKavxladYn6jpOXwEUBq03XuEX7c0 eUTqQEatA/+EMGVE8AHvOfYdXHDT1NuIwR+DJr3LqLK1I3zHr/6p7Rq57 Q==; X-CSE-ConnectionGUID: jRCzUENaSuSyaWHBNp2ORQ== X-CSE-MsgGUID: MNpx8SXbSF+D7sUZrjT+UA== X-IronPort-AV: E=Sophos;i="6.03,177,1694707200"; d="scan'208";a="249466771" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Sep 2023 18:02:50 +0800 IronPort-SDR: HrmON6gdSQ9L91UQ8DtvTlVqWR+DLcUsGJ/FdXUEgGomuJJOIXK2ZJ9bSHL7I+WTnJnxIAsNJq js3mc8DJrpXctnLvnc/V/U/bXVmOqGQuYDKYui6pq1lbdlEKtJOqtL17ldvojGlfzj+mN98/Mm phn7n0yEw3yScaDa+Hz78tSpjGEFswOul4uvp8rMHxUQ//ZIg2HWnqpA3c+E28nj/hn4shvQy/ iWev6Z9ThtkK83giML6wDJfyOvm4duAU1q1ALDAlpkXBm7Cj6gcTndi4hs7IXln33Od5plDIUj ink= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 26 Sep 2023 02:15:18 -0700 IronPort-SDR: sS5y1I1dHMh9QTLnOtWk0jizWeLPWwlyehT1mzdzcMAGaJXP9i5ERpTY9iW2p8N5wgAc2dMH9H Dz2oKh31bKWqJEO0SCz+83KZLChFOc79Q0e7uM2e5zF13SOrPfms0MgnFErXE6RZ4CmWpmytCK 1IjAxtmRYw7k8UVc6o1EUiV2DFZMCid7YOK+FV3nf2ElxDjlIZAOY21AnfPyZD6PhRDObqjarw kjOjb7BDw2AGh72YKJaJgoR9JqEzBaPymnICUgOf26j/pm3c4cxFFX06BblkeX0TQmUo3iWu+F xgA= WDCIronportException: Internal Received: from avri-office.ad.shared (HELO avri-office.sdcorp.global.sandisk.com) ([10.45.31.142]) by uls-op-cesaip02.wdc.com with ESMTP; 26 Sep 2023 03:02:49 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: wanggang26 Subject: [PATCH 5/5] mmc-utils: lsmmc: Fix emmc capacity calculation Date: Tue, 26 Sep 2023 13:00:06 +0300 Message-Id: <20230926100006.1789276-6-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230926100006.1789276-1-avri.altman@wdc.com> References: <20230926100006.1789276-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org From: wanggang26 When the device capacity is larger than 2GB, it shouldn't use c_size but instead it follows a different calculation using the SEC_COUNT field of the ext-csd[215:212] - see eMMC spec JESD84-B51 paragraph 7.3.12. This bug was already in lsmmc when it got merged into mmc-utils, hence the fixes tag. Fixes: 4af1749d2350 (mmc-utils: Merge the lsmmc tool into mmc-utils) Signed-off-by: wanggang26 --- lsmmc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lsmmc.c b/lsmmc.c index ef8fab1..b7d1c58 100644 --- a/lsmmc.c +++ b/lsmmc.c @@ -1819,6 +1819,9 @@ static void print_mmc_csd_capacity(unsigned int c_size, unsigned int c_size_mult int block_len = 1 << read_bl_len; unsigned long long memory_capacity; + if (c_size == 0xfff) + return; + printf("\tC_SIZE: 0x%03x\n", c_size); printf("\tC_SIZE_MULT: 0x%01x\n", c_size_mult);