From patchwork Wed Aug 7 06:03:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 817886 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAB02198E85 for ; Wed, 7 Aug 2024 06:04:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723010688; cv=none; b=nbl9RefMoNkQtv9tcNVXNqSsoqdLzh7JB87WSkUk4WLkMx09SKu5gYal7adSXjHc1S1eIsFMyXSbCBS7w+F6V/vvcmvsYo7lJPIPlrrx7WWOur9PnZ7fGuOzoRETQiD5PId/ArqGLc+rVTU9oBgIh3BuwxL8p198oFLlo3k5Ksk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723010688; c=relaxed/simple; bh=KQ34oRMswWKaUD5gQuHBgpKk5zj/IZmCJxdHEcJMn6o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=G45KqeeNfLnZgeQ8p1k3+wD09lEPplo3ih9Z6Pol/rKG3HL1ostOZGgEuDk84kCn8MAiI1saRGxQIhYDvvOP77nS/8l78ktOg9lmrgmCR+RBli33NYPh9JhuYqgnSNrpyDmv3fjzSsFSyv2w+BctSJdfmpSiVX3pqxXOJQ1fhY4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=KgNzgFYi; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="KgNzgFYi" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1723010686; x=1754546686; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KQ34oRMswWKaUD5gQuHBgpKk5zj/IZmCJxdHEcJMn6o=; b=KgNzgFYi0ygDBG5TRNnFIkczAJDLT+5RZLK9kK1s8R63IR1XNG6zSB52 VnI+LXGyyTHMvB5+4qUamtjsHh3KFt2yfM6k87p7GeB2WMmKDK2JQg6t+ mRk4nj28ASptA2d1HlR4ueGJVeGjPuVrgNhUK9VvdYUZx1trZNEuyrwQI emZDGkpiuKbPBAn2JZ1QGi50BI3CCIF5FNKg/HbLcyEP5VLoafHv1xxzi RbG3B7cmMIhoDxMA5FIWD+yQrLhw+oRc+hd12VEmKJaghhxl+fq4srdeF mXLp/RbSAAMSfwrwICB4KrIWDJJ8AVvryt6Fv3Zi7dLpnNFD6JDLAxQvZ g==; X-CSE-ConnectionGUID: 4OPcZMjyQQyorC99f955sA== X-CSE-MsgGUID: DOrojtcoRiq8NW/JAxSYuw== X-IronPort-AV: E=Sophos;i="6.09,269,1716220800"; d="scan'208";a="23039291" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 07 Aug 2024 14:04:46 +0800 IronPort-SDR: 66b30084_4LH6qeLgnjUr1UKTy5WZt6GmcMDkL3zmkHAukX/krFLFGho BhK2x3j7HRNmIMd2969T64RFNCiC+YjoqE031Ww== 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; 06 Aug 2024 22:05:08 -0700 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/TLS/ECDHE-RSA-AES128-GCM-SHA256; 06 Aug 2024 23:04:46 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Ricky WU , Avri Altman Subject: [PATCH v2 02/10] mmc: sd: Add SD CSD version 3.0 Date: Wed, 7 Aug 2024 09:03:01 +0300 Message-Id: <20240807060309.2403023-3-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240807060309.2403023-1-avri.altman@wdc.com> References: <20240807060309.2403023-1-avri.altman@wdc.com> Precedence: bulk X-Mailing-List: linux-mmc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Ultra Capacity SD cards (SDUC) was already introduced in SD7.0. Those cards support capacity larger than 2TB and up to including 128TB. Properly parse the csd register as the c_size field got expanded to 28 bits. Signed-off-by: Avri Altman --- drivers/mmc/core/bus.c | 4 +++- drivers/mmc/core/card.h | 3 +++ drivers/mmc/core/sd.c | 16 +++++++++++----- include/linux/mmc/card.h | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c index 0ddaee0eae54..30763b342bd3 100644 --- a/drivers/mmc/core/bus.c +++ b/drivers/mmc/core/bus.c @@ -321,7 +321,9 @@ int mmc_add_card(struct mmc_card *card) case MMC_TYPE_SD: type = "SD"; if (mmc_card_blockaddr(card)) { - if (mmc_card_ext_capacity(card)) + if (mmc_card_ult_capacity(card)) + type = "SDUC"; + else if (mmc_card_ext_capacity(card)) type = "SDXC"; else type = "SDHC"; diff --git a/drivers/mmc/core/card.h b/drivers/mmc/core/card.h index b7754a1b8d97..64dcb463a4f4 100644 --- a/drivers/mmc/core/card.h +++ b/drivers/mmc/core/card.h @@ -23,6 +23,7 @@ #define MMC_CARD_SDXC (1<<3) /* card is SDXC */ #define MMC_CARD_REMOVED (1<<4) /* card has been removed */ #define MMC_STATE_SUSPENDED (1<<5) /* card is suspended */ +#define MMC_CARD_SDUC (1<<6) /* card is SDUC */ #define mmc_card_present(c) ((c)->state & MMC_STATE_PRESENT) #define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY) @@ -30,11 +31,13 @@ #define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC) #define mmc_card_removed(c) ((c) && ((c)->state & MMC_CARD_REMOVED)) #define mmc_card_suspended(c) ((c)->state & MMC_STATE_SUSPENDED) +#define mmc_card_ult_capacity(c) ((c)->state & MMC_CARD_SDUC) #define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT) #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY) #define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR) #define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC) +#define mmc_card_set_ult_capacity(c) ((c)->state |= MMC_CARD_SDUC) #define mmc_card_set_removed(c) ((c)->state |= MMC_CARD_REMOVED) #define mmc_card_set_suspended(c) ((c)->state |= MMC_STATE_SUSPENDED) #define mmc_card_clr_suspended(c) ((c)->state &= ~MMC_STATE_SUSPENDED) diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 1c8148cdda50..28193a9b31c9 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -157,6 +157,7 @@ static int mmc_decode_csd(struct mmc_card *card) mmc_card_set_readonly(card); break; case 1: + case 2: /* * This is a block-addressed SDHC or SDXC card. Most * interesting fields are unused and have fixed @@ -172,14 +173,19 @@ static int mmc_decode_csd(struct mmc_card *card) e = UNSTUFF_BITS(resp, 96, 3); csd->max_dtr = tran_exp[e] * tran_mant[m]; csd->cmdclass = UNSTUFF_BITS(resp, 84, 12); - csd->c_size = UNSTUFF_BITS(resp, 48, 22); - /* SDXC cards have a minimum C_SIZE of 0x00FFFF */ - if (csd->c_size >= 0xFFFF) + if (csd_struct == 1) + m = UNSTUFF_BITS(resp, 48, 22); + else + m = UNSTUFF_BITS(resp, 48, 28); + csd->c_size = m; + + if (csd->c_size >= 0x400000 && mmc_card_is_sduc(card->host)) + mmc_card_set_ult_capacity(card); + else if (csd->c_size >= 0xFFFF) mmc_card_set_ext_capacity(card); - m = UNSTUFF_BITS(resp, 48, 22); - csd->capacity = (1 + m) << 10; + csd->capacity = (1 + (typeof(sector_t))m) << 10; csd->read_blkbits = 9; csd->read_partial = 0; diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index f34407cc2788..f39bce322365 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -35,7 +35,7 @@ struct mmc_csd { unsigned int wp_grp_size; unsigned int read_blkbits; unsigned int write_blkbits; - unsigned int capacity; + sector_t capacity; unsigned int read_partial:1, read_misalign:1, write_partial:1, From patchwork Wed Aug 7 06:03:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 817885 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98A8E198E85 for ; Wed, 7 Aug 2024 06:04:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723010695; cv=none; b=IoOX3LRKjQQQCBOf0rWef7Z6aGQ35RF0BQ34YvAgQuW5474gW5gLQBTWMke7pmSyNtbTvyac5vfzTBaQ/TREr21/D9UfCBnxQBhWm9+DkGXMKvp8iT7q5KK8VYUb7ONY0AEEsRH9oSlYGpawjU2JPaMyyn6/0VQc55zz0x7jJqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723010695; c=relaxed/simple; bh=MHFndB2QnUNxORquhxbFIL559YwED7RczyN5weD7NGA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ta+FPX1ekuzPw1zC+wt49W9dSNPmkUVblvdXnwUIgiRJOgo5wKI0B7ZI/1Ll4N5kjDHo4vXr9pr6UVLE2/Y/CndazUbEphza36WXCFYP0zrxlsdjL3ne9tF8qbSFQKDa5l0y9SEJkFGhtIv8yPEoLsdaGUUDu6Cm3YtBpvypY2c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=OfcbR8Jp; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="OfcbR8Jp" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1723010693; x=1754546693; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MHFndB2QnUNxORquhxbFIL559YwED7RczyN5weD7NGA=; b=OfcbR8JpiTYdmfYMqIxZJQPajWdees1Y1meIMvrP7/3iXIhqR5Ss2pEZ LH92a//4o4a1J8USPir9D66LSSEfxXMFEKEQA7GcLEOde3DxG704EbgKB u29GZ3pTShq0K2cg6olPU9iGSYJItIlrCTqn64+Z3UxyfqholF+sHB0iH FdN4V7/5A1LNmGdGxCNcuoH4bgKb1Zx2I5r+r7gvC0EgPyoUGTKt4az0S 3GjvhYgtETp8m8wqKjY43dP+e9s18zo/lzTn7Q5zG2Hv28Dbj7XsnVvoj Br8i/3c5iBfrj6CY/xgEbfhAUTpcXZepZunr9A8pSTBQbdpFqDZSk0v21 g==; X-CSE-ConnectionGUID: 5+xjMRaoSK6PQMzp2s5PCw== X-CSE-MsgGUID: rZJX4PSaQHa6+05pwvOMNg== X-IronPort-AV: E=Sophos;i="6.09,269,1716220800"; d="scan'208";a="23039305" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 07 Aug 2024 14:04:53 +0800 IronPort-SDR: 66b3008b_9PK0d7kqjssOuJNcDLbMPNT1413bdOpEPUiQRBRO5Iacij9 ghNgzgg3DAfWVmJYegOov5OgZ7LBi35QNGZiCRA== 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; 06 Aug 2024 22:05:15 -0700 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/TLS/ECDHE-RSA-AES128-GCM-SHA256; 06 Aug 2024 23:04:53 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Ricky WU , Avri Altman Subject: [PATCH v2 04/10] mmc: core: Add open-ended Ext memory addressing Date: Wed, 7 Aug 2024 09:03:03 +0300 Message-Id: <20240807060309.2403023-5-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240807060309.2403023-1-avri.altman@wdc.com> References: <20240807060309.2403023-1-avri.altman@wdc.com> Precedence: bulk X-Mailing-List: linux-mmc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For open-ended read/write - just send CMD22 before issuing the command. While at it, make sure that the rw command arg is properly casting the lower 32 bits, as it can be larger now. Signed-off-by: Avri Altman --- drivers/mmc/core/block.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 367509b5b646..392621232ad8 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -180,6 +180,7 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq, static void mmc_blk_hsq_req_done(struct mmc_request *mrq); static int mmc_spi_err_check(struct mmc_card *card); static int mmc_blk_busy_cb(void *cb_data, bool *busy); +static int mmc_blk_wait_for_idle(struct mmc_queue *mq, struct mmc_host *host); static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk) { @@ -1664,7 +1665,7 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq, brq->mrq.cmd = &brq->cmd; - brq->cmd.arg = blk_rq_pos(req); + brq->cmd.arg = blk_rq_pos(req) & 0xFFFFFFFF; if (!mmc_card_blockaddr(card)) brq->cmd.arg <<= 9; brq->cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; @@ -1712,6 +1713,9 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq, (do_data_tag ? (1 << 29) : 0); brq->sbc.flags = MMC_RSP_R1 | MMC_CMD_AC; brq->mrq.sbc = &brq->sbc; + } else if (mmc_card_is_sduc(card->host)) { + mmc_blk_wait_for_idle(mq, card->host); + mmc_send_ext_addr(card->host, blk_rq_pos(req)); } } From patchwork Wed Aug 7 06:03:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 817884 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AA75198E90 for ; Wed, 7 Aug 2024 06:05:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723010701; cv=none; b=gu035J1tU1z5b4juHbzstC8XLgJ6MJnBXp1o4u7b1LPW5o2zvAOXGIA344Da0HQeZQWG8162cNPch/DwDGWRxhHv5nfQC6zPzsG2CNtGj2bh7R5b5atzAvtxWAAEt7n/bOHaBjFQJ3VV8oc/K5eboR24dtB++AfdGIuAlT8GkWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723010701; c=relaxed/simple; bh=oG+rXt7cEqPZX9VNLCZ/g6/9uNIBC2w1APBThzfqA4o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s8s6nbUTe8OXQ9ER3jf69ZrEmcG7RgCKZjg4hkZ4t2ntEQt+By9rbQDghW200Yl5v86lemjt3KAYaBLITIUirnD8+iUP1520PxByDB7E7STTo2OqTYge+VTOW/OKFYrrL6pvAXH/xRjMAbJfc26o2WEFzus2tKOrpaBFXLb61CI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=TsCX61y0; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="TsCX61y0" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1723010700; x=1754546700; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oG+rXt7cEqPZX9VNLCZ/g6/9uNIBC2w1APBThzfqA4o=; b=TsCX61y0ORFe7yh8/kAxtYQX/9SjYuSu9MPsgL+0yjQUpg34vV3GCfw/ I2F3rW9xt07xnf+qdHjb6jpvvzjAJ1jRx4eiF95nwskf9YubqHCR/gfTI OyEqJ/zNpnnuEgLl0S06DdS2Dod42xCmN/UIHK65BSTORHldVGvpyZCht XEER4cbSi6+IjqzoaMBVWDmCdSomIPxvk/y/lV9GxJ72mXbj+V+RfPdQX Wun6cnqOkqj9hbI+9Uw/gQ7Nqxnn7l7Qn+jUpfznmAKQhlJ/rU2f/YJLL inThh2GOQuHI+Lzdh5u19jrFwDyWLPsNluUipX53UOi0gpyiojTwK2qqE A==; X-CSE-ConnectionGUID: AoBsIqHWTIKThOs+YBgb8g== X-CSE-MsgGUID: b7GcAWbWQpiHSimoLR+HdQ== X-IronPort-AV: E=Sophos;i="6.09,269,1716220800"; d="scan'208";a="23039316" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 07 Aug 2024 14:05:00 +0800 IronPort-SDR: 66b30091_vl6OnTE1aUyKb0FJzS04iKloNyQAol6mzxPEGBbz8bzFZt2 eYYQvyfOCtb1mXUbwFJ7T7RBxLwCW5/7ZK8MB+w== 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; 06 Aug 2024 22:05:22 -0700 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/TLS/ECDHE-RSA-AES128-GCM-SHA256; 06 Aug 2024 23:04:59 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Ricky WU , Avri Altman Subject: [PATCH v2 06/10] mmc: core: Add close-ended Ext memory addressing Date: Wed, 7 Aug 2024 09:03:05 +0300 Message-Id: <20240807060309.2403023-7-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240807060309.2403023-1-avri.altman@wdc.com> References: <20240807060309.2403023-1-avri.altman@wdc.com> Precedence: bulk X-Mailing-List: linux-mmc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In a multi-block data transfer, CMD23 shall precede CMD22. Prepare CMD22 in advance as an additional extension of the mrq, to be handle by the host once CMD23 is done. Signed-off-by: Avri Altman --- drivers/mmc/core/block.c | 7 +++++++ drivers/mmc/core/core.c | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 392621232ad8..abf1e8a124a5 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -1713,6 +1713,13 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq, (do_data_tag ? (1 << 29) : 0); brq->sbc.flags = MMC_RSP_R1 | MMC_CMD_AC; brq->mrq.sbc = &brq->sbc; + + if (mmc_card_is_sduc(card->host)) { + brq->ext.opcode = SD_ADDR_EXT; + brq->ext.arg = (u32)((blk_rq_pos(req) >> 32) & 0x3F); + brq->ext.flags = MMC_RSP_R1 | MMC_CMD_AC; + brq->mrq.ext = &brq->ext; + } } else if (mmc_card_is_sduc(card->host)) { mmc_blk_wait_for_idle(mq, card->host); mmc_send_ext_addr(card->host, blk_rq_pos(req)); diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index d6c819dd68ed..754e628b061b 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -184,6 +184,14 @@ void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq) mrq->sbc->resp[2], mrq->sbc->resp[3]); } + if (mrq->ext) { + pr_debug("%s: req done : %d: %08x %08x %08x %08x\n", + mmc_hostname(host), mrq->ext->opcode, + mrq->ext->error, + mrq->ext->resp[0], mrq->ext->resp[1], + mrq->ext->resp[2], mrq->ext->resp[3]); + } + pr_debug("%s: req done (CMD%u): %d: %08x %08x %08x %08x\n", mmc_hostname(host), cmd->opcode, err, cmd->resp[0], cmd->resp[1], @@ -270,6 +278,12 @@ static void mmc_mrq_pr_debug(struct mmc_host *host, struct mmc_request *mrq, mrq->sbc->arg, mrq->sbc->flags); } + if (mrq->ext) { + pr_debug("<%s: starting CMD%u arg %08x flags %08x>\n", + mmc_hostname(host), mrq->ext->opcode, + mrq->ext->arg, mrq->ext->flags); + } + if (mrq->cmd) { pr_debug("%s: starting %sCMD%u arg %08x flags %08x\n", mmc_hostname(host), cqe ? "CQE direct " : "", @@ -309,6 +323,10 @@ static int mmc_mrq_prep(struct mmc_host *host, struct mmc_request *mrq) mrq->sbc->error = 0; mrq->sbc->mrq = mrq; } + if (mrq->ext) { + mrq->ext->error = 0; + mrq->ext->mrq = mrq; + } if (mrq->data) { if (mrq->data->blksz > host->max_blk_size || mrq->data->blocks > host->max_blk_count || From patchwork Wed Aug 7 06:03:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 817883 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2289198E86 for ; Wed, 7 Aug 2024 06:05:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723010708; cv=none; b=OTTcSLGZuZPG9Dy7pNGoaKPLDEizr15T6VRgCZXAA/S0tB8wg5o2IG/k40X3D54sVUIVfqTJi1Npe/1zg/9QLN2+AIB1L3qgck2G/DyyW9zrtKj564KD2p7mOQXvRTxvRLh7mmWSmnFYGWW9aTLYT5JHEpchT0ryHPGhPx3tF3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723010708; c=relaxed/simple; bh=Wcj/mjpTmCbjL+Xssf02Wc9rFe9DuiBgVw5VCokqUaM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RLGB24+yOOObBRyHwX3dxxo9U46gJmnD16HthdOuL1F/yTA5Bwmv7IWDWcUQEYTxOiaY2AIw7bGNJJ84CC1CiC3ggChWb8CZvYZobdV1vsO6AkRfr2WxhaquNxVPduu+H1XzZtR2YFvdaL9YZMvrG6aDY2GkTVxxcSY9IpDaJZI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=NOEAb1cm; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="NOEAb1cm" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1723010706; x=1754546706; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Wcj/mjpTmCbjL+Xssf02Wc9rFe9DuiBgVw5VCokqUaM=; b=NOEAb1cmE2Q84+sLWTKdJQoBFmlrF7/tU/p6f1sg4fe6K2fO43EiokoT KM8Xxa95GvJO2OM9kDJGsStFCwl2+C7RqqPpA7LexA7oIbc0sg1Xfhgxn ED2YsjTlMOmoaFDq+v6LVCdfTfikBtOtfQH1qn7PIXiuuhSeIwasZ9hgU z06FbJkI7Qx8CIsdAkuFnJN3U0UcA1Lxf1Iqy4fz8rKTE0ltkPNsYvg0N +0eRPr1Tu0c3mVSV+6K+6VMKa3NIc6/f7JU+40lw7PaOLPJXgnsp/wM7V AgT3+ArLCdQ0xVezz7O+8nlOdZ2N21gkfLunlyVfys6ZPzSLvC3uphCzQ Q==; X-CSE-ConnectionGUID: t1dMmJ3/SwWKMPwsxWm/sA== X-CSE-MsgGUID: MU7aajEhSM2zBUr3XR2JKg== X-IronPort-AV: E=Sophos;i="6.09,269,1716220800"; d="scan'208";a="23039327" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 07 Aug 2024 14:05:06 +0800 IronPort-SDR: 66b30098_JnMCyhjUz2ySKUo1lKRg9mVE12O6QZYLQkvl9cPiVPuF51K ImJYkNOIELkAhwvqh7yxrAjabmfkcRGt4EpxE0g== 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; 06 Aug 2024 22:05:28 -0700 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/TLS/ECDHE-RSA-AES128-GCM-SHA256; 06 Aug 2024 23:05:06 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Ricky WU , Avri Altman Subject: [PATCH v2 08/10] mmc: core: Allow mmc erase to carry large addresses Date: Wed, 7 Aug 2024 09:03:07 +0300 Message-Id: <20240807060309.2403023-9-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240807060309.2403023-1-avri.altman@wdc.com> References: <20240807060309.2403023-1-avri.altman@wdc.com> Precedence: bulk X-Mailing-List: linux-mmc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Preparing for SDUC, Allow the erase address to be larger beyond a 32 bit address. Signed-off-by: Avri Altman --- drivers/mmc/core/block.c | 6 ++++-- drivers/mmc/core/core.c | 18 ++++++++++-------- drivers/mmc/core/core.h | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index abf1e8a124a5..55b9fc34fdd4 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -1154,7 +1154,8 @@ static void mmc_blk_issue_erase_rq(struct mmc_queue *mq, struct request *req, { struct mmc_blk_data *md = mq->blkdata; struct mmc_card *card = md->queue.card; - unsigned int from, nr; + unsigned int nr; + sector_t from; int err = 0; blk_status_t status = BLK_STS_OK; @@ -1209,7 +1210,8 @@ static void mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq, { struct mmc_blk_data *md = mq->blkdata; struct mmc_card *card = md->queue.card; - unsigned int from, nr, arg; + unsigned int nr, arg; + sector_t from; int err = 0, type = MMC_BLK_SECDISCARD; blk_status_t status = BLK_STS_OK; diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 754e628b061b..8ea28a04e438 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1616,8 +1616,8 @@ static unsigned int mmc_erase_timeout(struct mmc_card *card, return mmc_mmc_erase_timeout(card, arg, qty); } -static int mmc_do_erase(struct mmc_card *card, unsigned int from, - unsigned int to, unsigned int arg) +static int mmc_do_erase(struct mmc_card *card, sector_t from, + sector_t to, unsigned int arg) { struct mmc_command cmd = {}; unsigned int qty = 0, busy_timeout = 0; @@ -1718,18 +1718,19 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from, } static unsigned int mmc_align_erase_size(struct mmc_card *card, - unsigned int *from, - unsigned int *to, + sector_t *from, + sector_t *to, unsigned int nr) { - unsigned int from_new = *from, nr_new = nr, rem; + sector_t from_new = *from; + unsigned int nr_new = nr, rem; /* * When the 'card->erase_size' is power of 2, we can use round_up/down() * to align the erase size efficiently. */ if (is_power_of_2(card->erase_size)) { - unsigned int temp = from_new; + sector_t temp = from_new; from_new = round_up(temp, card->erase_size); rem = from_new - temp; @@ -1774,10 +1775,11 @@ static unsigned int mmc_align_erase_size(struct mmc_card *card, * * Caller must claim host before calling this function. */ -int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr, +int mmc_erase(struct mmc_card *card, sector_t from, unsigned int nr, unsigned int arg) { - unsigned int rem, to = from + nr; + unsigned int rem; + sector_t to = from + nr; int err; if (!(card->csd.cmdclass & CCC_ERASE)) diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h index 37091a6589ed..faae4b6404ad 100644 --- a/drivers/mmc/core/core.h +++ b/drivers/mmc/core/core.h @@ -116,7 +116,7 @@ bool mmc_is_req_done(struct mmc_host *host, struct mmc_request *mrq); int mmc_start_request(struct mmc_host *host, struct mmc_request *mrq); -int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr, +int mmc_erase(struct mmc_card *card, sector_t from, unsigned int nr, unsigned int arg); int mmc_can_erase(struct mmc_card *card); int mmc_can_trim(struct mmc_card *card); From patchwork Wed Aug 7 06:03:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 817882 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36A48198E86 for ; Wed, 7 Aug 2024 06:05:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.154.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723010715; cv=none; b=M1/nrQPnHHsVaush7gGc3W3DjuGmGsUKBU8rTLfAuWa9Y0aV3cKx7W5WGOjdHRDgRPjII99RbfZxJw6Mv3UF042liULlIwRHhRNZ4QepuyiKuN3tnrRWBiXVeEMelY0VcT/+tbN35iAl3XOPiDiXE5l6A+lKVJEqGOE4ezzrLTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723010715; c=relaxed/simple; bh=k4mDYAkeb/fiZjjyfKZZvjDoyB3+P9fEVHfV+YOvaOw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JOD7SgHOgkdkPzX0707F7ZfNlxoToJKunCHdxvn88oPdRP5UzvweZ2wGFGsr96ENqLEh1HletmQXxvz6PhJJPo2anjJxxXqH5nNB1BUXPg5wa0C8BlyzT0ZClW750HFsPw2um32/3Nc+XfwO8HH15giIW6/ZiLa2XsjmFdhA4UE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=rRltALGE; arc=none smtp.client-ip=216.71.154.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="rRltALGE" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1723010713; x=1754546713; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=k4mDYAkeb/fiZjjyfKZZvjDoyB3+P9fEVHfV+YOvaOw=; b=rRltALGE8lqTIxOXpCLZJ5a1nLy17lvTcQOKd9pjihva2xVSOuEc/0Q+ 0w6KY5YwLifTyxmAnVEtKOHb3qs0IyUMulXSqFdD1D5HN6nmD0fo3UyKt nXdH8+ZJB07Z28qEkIlNlZRnHoXK3N/t6Tvyv+iQL6UBy6UoXmMUHjlSR dKD2Eu3seNYu8glt0iHDG1bP5JyY7MCGX7Ej3EDQDksSuJfHh9IYivs9a n3g8oV/jx8X1xdllriaHWo9UOo0CVicGIOMhRKdcoNKkHgtmr71JXYJrf sID81snkv0cOA0HRXZjmeoNLHcES4sUm/8h+7P+TC7M3Op6CRjWzlEbD1 w==; X-CSE-ConnectionGUID: zlx8++V2SvuQK86Emutq+g== X-CSE-MsgGUID: H3CaxLQlQ0Obyup/+zlSLw== X-IronPort-AV: E=Sophos;i="6.09,269,1716220800"; d="scan'208";a="23039345" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 07 Aug 2024 14:05:13 +0800 IronPort-SDR: 66b3009e_25zw/x2N+bQ5ijwE2aJt6bQhqD2AAjwYAFuAILmqdgPdK2D IjxiOT7ybIX7t6vygDEWMJ3JqnNUWzc/QPmhDBg== 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; 06 Aug 2024 22:05:35 -0700 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/TLS/ECDHE-RSA-AES128-GCM-SHA256; 06 Aug 2024 23:05:12 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Ricky WU , Avri Altman Subject: [PATCH v2 10/10] mmc: core: Adjust ACMD22 to SDUC Date: Wed, 7 Aug 2024 09:03:09 +0300 Message-Id: <20240807060309.2403023-11-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240807060309.2403023-1-avri.altman@wdc.com> References: <20240807060309.2403023-1-avri.altman@wdc.com> Precedence: bulk X-Mailing-List: linux-mmc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 ACMD22 is used to verify the previously write operation. Normally, it returns the number of written sectors as u32. SDUC, however, returns it as u64. This is a superfluous requirement, as the previously write operation could not be more than the block layer limits, just make room for a u64 and ignore the 2nd dword. Moreover, SD cards expect to be allowed the full 500msec busy period post write operations. This is true for standard capacity SD, and even more so for high volume SD cards, specifically SDUC. If CMD13 return an error bit, the recovery flow is entered regardless of the busy period. Thus, better enforce the busy period for SDUC, otherwise it might return a bogus bytes written. Signed-off-by: Avri Altman --- drivers/mmc/core/block.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 55b9fc34fdd4..cb268af26982 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -948,13 +948,20 @@ static int mmc_sd_num_wr_blocks(struct mmc_card *card, u32 *written_blocks) int err; u32 result; __be32 *blocks; - + u8 resp_sz; struct mmc_request mrq = {}; struct mmc_command cmd = {}; struct mmc_data data = {}; - struct scatterlist sg; + /* + * SD cards, specifically high volume cards, expect to be allowed with the + * full 500msec busy period post write. Otherwise, they may not indicate + * correctly the number of bytes written. + */ + if (mmc_card_is_sduc(card->host)) + mmc_delay(500); + err = mmc_app_cmd(card->host, card); if (err) return err; @@ -963,7 +970,16 @@ static int mmc_sd_num_wr_blocks(struct mmc_card *card, u32 *written_blocks) cmd.arg = 0; cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; - data.blksz = 4; + /* + * Normally, ACMD22 returns the number of written sectors as u32. + * SDUC, however, returns it as u64. This is a superfluous + * requirement, as the previously write operation could not be more + * than the block layer limits, just make room for a u64 and ignore + * the 2nd dword. + */ + resp_sz = mmc_card_is_sduc(card->host) ? 8 : 4; + + data.blksz = resp_sz; data.blocks = 1; data.flags = MMC_DATA_READ; data.sg = &sg; @@ -973,11 +989,11 @@ static int mmc_sd_num_wr_blocks(struct mmc_card *card, u32 *written_blocks) mrq.cmd = &cmd; mrq.data = &data; - blocks = kmalloc(4, GFP_KERNEL); + blocks = kmalloc(resp_sz, GFP_KERNEL); if (!blocks) return -ENOMEM; - sg_init_one(&sg, blocks, 4); + sg_init_one(&sg, blocks, resp_sz); mmc_wait_for_req(card->host, &mrq);