From patchwork Sun Aug 25 07:41:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 822562 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (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 1BC2257CBA for ; Sun, 25 Aug 2024 07:43:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724571807; cv=none; b=VGDigCW38w6pNHbEqO+5YlmvBsgU3W8rJA/XtYa4mrpfQUF/ftnIQSOQZG1yS8i7BNo5IrmiRAmgTmoy9X5cOOQd9EJz8UEMaai7bqNfTDuIuh58ezfxK5JoYMujaQhvTdUJws50V/DK1u1MyQ9b6uATZ7Tp1cZSZx8ANYlKgeM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724571807; c=relaxed/simple; bh=/l6HaLIOBBwAPk01aGCtSE0tuz0tJYIXwKVVcEBR+iE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eCpdJqcRS5knVtpfS8P07d4hirlynSppsIc7w8OHeq73wnrGg6eQky/LyETUl9rWFvL/hHLgAnjqsDya+iCUkZGyQwJoxya+4gZg+qJ5C3ew88ZDCJd95Gc+rJHUGKWAvviZw3hRFTHenKS4kO6kQzLKJzC15u0Lg0n89BEYxNM= 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=eoiEytLb; arc=none smtp.client-ip=216.71.153.141 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="eoiEytLb" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1724571805; x=1756107805; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/l6HaLIOBBwAPk01aGCtSE0tuz0tJYIXwKVVcEBR+iE=; b=eoiEytLbcqzofGmce9wJHbOz3OfpOT0ebaLSN+zsLvfKDk0P6uNeTxxK Whhr12BHmC9N8RH0//D2+yp8lReM3RREV4E/mqntk+6WXbLKvFbdMuVBR J5d4+0ucHVaervaoIXC/Kj+ZV3GdOg/lO8ByEiYVgze5FG7U1jxc6Bn/2 gEoOJFXmB06nOdPx+uTSkPyZGymx6N0TY0fyTEkdIAez/X5dtnAzZ3EyB X1SFJKXw9hBLlBCRB7C+4QCQGLiAtq+iyJUhfbX6GPJLHHVFFVaoV+IRm oNyWF/1ZrUUOSwKMBYyxB4zX9m7CwYFbx6QUQ2Z0423AncMH2vFOqD/NB w==; X-CSE-ConnectionGUID: rMBNQY1rTIac6XqB5P56Kg== X-CSE-MsgGUID: oc4U7V6KSOWK26q2eQvGTA== X-IronPort-AV: E=Sophos;i="6.10,175,1719849600"; d="scan'208";a="25100414" 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; 25 Aug 2024 15:43:21 +0800 IronPort-SDR: 66cad3dc_dJYxjcOsmhKGwDgms+HTD/AzoTk8wSMrdrDpbk3/dAHY13w m2HbyrM8npDiYq1r4AghKQNBQjffzq/3idZwZtw== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Aug 2024 23:49:00 -0700 WDCIronportException: Internal Received: from avri-office.ad.shared (HELO avri-office.sdcorp.global.sandisk.com) ([10.45.31.142]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Aug 2024 00:43:19 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Adrian Hunter , Ricky WU , Avri Altman Subject: [PATCH v4 1/9] mmc: sd: SDUC Support Recognition Date: Sun, 25 Aug 2024 10:41:33 +0300 Message-Id: <20240825074141.3171549-2-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240825074141.3171549-1-avri.altman@wdc.com> References: <20240825074141.3171549-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. ACMD41 was extended to support the host-card handshake during initialization. The card expects that the HCS & HO2T bits to be set in the command argument, and sets the applicable bits in the R3 returned response. On the contrary, if a SDUC card is inserted to a non-supporting host, it will never respond to this ACMD41 until eventually, the host will timed out and give up. Also, add SD CSD version 3.0 - designated for SDUC, and properly parse the csd register as the c_size field got expanded to 28 bits. Tested-by: Ricky WU Signed-off-by: Avri Altman --- drivers/mmc/core/bus.c | 4 +++- drivers/mmc/core/card.h | 3 +++ drivers/mmc/core/sd.c | 36 ++++++++++++++++++++++++------------ drivers/mmc/core/sd.h | 2 +- drivers/mmc/core/sdio.c | 2 +- include/linux/mmc/card.h | 2 +- include/linux/mmc/sd.h | 1 + 7 files changed, 34 insertions(+), 16 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..616bd7d5915d 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -113,7 +113,7 @@ void mmc_decode_cid(struct mmc_card *card) /* * Given a 128-bit response, decode to our card CSD structure. */ -static int mmc_decode_csd(struct mmc_card *card) +static int mmc_decode_csd(struct mmc_card *card, bool is_sduc) { struct mmc_csd *csd = &card->csd; unsigned int e, m, csd_struct; @@ -157,9 +157,10 @@ 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 + * This is a block-addressed SDHC, SDXC or SDUC card. + * Most interesting fields are unused and have fixed * values. To avoid getting tripped by buggy cards, * we assume those fixed values ourselves. */ @@ -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 && is_sduc) + 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; @@ -840,8 +846,11 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr) * block-addressed SDHC cards. */ err = mmc_send_if_cond(host, ocr); - if (!err) + if (!err) { ocr |= SD_OCR_CCS; + /* Set HO2T as well - SDUC card won't respond otherwise */ + ocr |= SD_OCR_2T; + } /* * If the host supports one of UHS-I modes, request the card @@ -886,7 +895,7 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr) return err; } -int mmc_sd_get_csd(struct mmc_card *card) +int mmc_sd_get_csd(struct mmc_card *card, bool is_sduc) { int err; @@ -897,7 +906,7 @@ int mmc_sd_get_csd(struct mmc_card *card) if (err) return err; - err = mmc_decode_csd(card); + err = mmc_decode_csd(card, is_sduc); if (err) return err; @@ -1452,7 +1461,10 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, } if (!oldcard) { - err = mmc_sd_get_csd(card); + u32 sduc_arg = SD_OCR_CCS | SD_OCR_2T; + bool is_sduc = (rocr & sduc_arg) == sduc_arg; + + err = mmc_sd_get_csd(card, is_sduc); if (err) goto free_card; diff --git a/drivers/mmc/core/sd.h b/drivers/mmc/core/sd.h index fe6dd46927a4..7e8beface2ca 100644 --- a/drivers/mmc/core/sd.h +++ b/drivers/mmc/core/sd.h @@ -10,7 +10,7 @@ struct mmc_host; struct mmc_card; int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr); -int mmc_sd_get_csd(struct mmc_card *card); +int mmc_sd_get_csd(struct mmc_card *card, bool is_sduc); void mmc_decode_cid(struct mmc_card *card); int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card, bool reinit); diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index 4fb247fde5c0..9566837c9848 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c @@ -769,7 +769,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, * Read CSD, before selecting the card */ if (!oldcard && mmc_card_sd_combo(card)) { - err = mmc_sd_get_csd(card); + err = mmc_sd_get_csd(card, false); if (err) goto remove; 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, diff --git a/include/linux/mmc/sd.h b/include/linux/mmc/sd.h index 6727576a8755..865cc0ca8543 100644 --- a/include/linux/mmc/sd.h +++ b/include/linux/mmc/sd.h @@ -36,6 +36,7 @@ /* OCR bit definitions */ #define SD_OCR_S18R (1 << 24) /* 1.8V switching request */ #define SD_ROCR_S18A SD_OCR_S18R /* 1.8V switching accepted by card */ +#define SD_OCR_2T (1 << 27) /* HO2T/CO2T - SDUC support */ #define SD_OCR_XPC (1 << 28) /* SDXC power control */ #define SD_OCR_CCS (1 << 30) /* Card Capacity Status */ From patchwork Sun Aug 25 07:41:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 822418 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (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 0028B17C64 for ; Sun, 25 Aug 2024 07:43:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724571807; cv=none; b=dSjdQGgWZBpfJ/FdLLtdpbqaDRcHPkYCWMeAYJI2Af38u9hx8YVMoG7u/wf6uPbLPj0Gvu4KC/xjZ+enHg8EwuNx0j88w+gZaZQ6P3X1M6OJjBaRP67aSnpc1n0w35cKXLDoCflAD23/MbMBy4Et/nHyrj+L0seRS9XTg0unZSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724571807; c=relaxed/simple; bh=Zg5j+3+EJ3+UYUWuGhE5R/+Nn+j0oXQyYnXnwkRUz1A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TrCkiYgv4uTpl+U71szESqsscOlE80+aBFeBhjWKPlnTHv4PSsN6BbZqee9W/YqOAtDwrocwx5qTi8983qDW22eOkG54iHxpv9wlMloFdQyV4gDnlXjN4xaVmtQPDGI9jPcU71qkEcjTsPj4C6AbtCQA3xcv/o7JIDyyLuwc8aI= 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=UWksceQK; arc=none smtp.client-ip=216.71.153.141 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="UWksceQK" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1724571806; x=1756107806; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Zg5j+3+EJ3+UYUWuGhE5R/+Nn+j0oXQyYnXnwkRUz1A=; b=UWksceQKSODEf9Hi6DmVWTyu7yxwE31a/qWfeFCAkvM0LqOW9q/cayw5 cDaWVXQfb0q1z1EyzCgK88DDOmCvVWrHA1fP58MLLuHyvBgcmIhkkijZN 5esWgqTCsuilBI7YPe8Gq8xbMGsrKjUN/SWbd7wSYQW50ApIX4sqRJpXt zJksBSIqmlVWKDu4QWrRyPdxj0tBnG+wUHhkJpULYJ6QaXE/wNAH9+UJ9 03E7JyNDw00p3gzY++Vck+1FQBim8jwCTbTYkPeT7L0yxadbImclrMbyz DaNQtiyu3ymXD99wY4bNVCILfGrtfieipf10OhtA/0DpLDdMVCg0FiuVq A==; X-CSE-ConnectionGUID: mg53y5zOQU2ZMsfgIB9iwg== X-CSE-MsgGUID: fW8Ww/pcS9en80WQ7iBN+Q== X-IronPort-AV: E=Sophos;i="6.10,175,1719849600"; d="scan'208";a="25100417" 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; 25 Aug 2024 15:43:24 +0800 IronPort-SDR: 66cad3e0_zIH9SIl85lZJkTrVx1h8xD6LA+mxijWXZvyhd+GIdHzy7w9 GhQD2NIvSEndBZ/H+P94n7LxhQ57istNk3IKbcA== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Aug 2024 23:49:04 -0700 WDCIronportException: Internal Received: from avri-office.ad.shared (HELO avri-office.sdcorp.global.sandisk.com) ([10.45.31.142]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Aug 2024 00:43:23 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Adrian Hunter , Ricky WU , Avri Altman Subject: [PATCH v4 2/9] mmc: sd: Add Extension memory addressing Date: Sun, 25 Aug 2024 10:41:34 +0300 Message-Id: <20240825074141.3171549-3-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240825074141.3171549-1-avri.altman@wdc.com> References: <20240825074141.3171549-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 SDUC memory addressing spans beyond 2TB and up to 128TB. Therefore, 38 bits are required to access the entire memory space of all sectors. Those extra 6 bits are to be carried by CMD22 prior of sending read/write/erase commands: CMD17, CMD18, CMD24, CMD25, CMD32, and CMD33. CMD22 will carry the higher order 6 bits, and must precedes any of the above commands even if it targets sector < 2TB. No error related to address or length is indicated in CMD22 but rather in the read/write command itself. Tested-by: Ricky WU Signed-off-by: Avri Altman --- drivers/mmc/core/sd_ops.c | 16 ++++++++++++++++ drivers/mmc/core/sd_ops.h | 1 + include/linux/mmc/sd.h | 3 +++ 3 files changed, 20 insertions(+) diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c index 8b9b34286ef3..780c5dd7266f 100644 --- a/drivers/mmc/core/sd_ops.c +++ b/drivers/mmc/core/sd_ops.c @@ -16,6 +16,7 @@ #include #include "core.h" +#include "card.h" #include "sd_ops.h" #include "mmc_ops.h" @@ -188,6 +189,21 @@ int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr) return 0; } +int mmc_send_ext_addr(struct mmc_host *host, sector_t addr) +{ + struct mmc_command cmd = { + .opcode = SD_ADDR_EXT, + .arg = (u32)((addr >> 32) & 0x3F), + .flags = MMC_RSP_R1 | MMC_CMD_AC, + }; + + if (!mmc_card_ult_capacity(host->card)) + return 0; + + return mmc_wait_for_cmd(host, &cmd, 0); +} +EXPORT_SYMBOL_GPL(mmc_send_ext_addr); + static int __mmc_send_if_cond(struct mmc_host *host, u32 ocr, u8 pcie_bits, u32 *resp) { diff --git a/drivers/mmc/core/sd_ops.h b/drivers/mmc/core/sd_ops.h index 7667fc223b74..462efd43acfa 100644 --- a/drivers/mmc/core/sd_ops.h +++ b/drivers/mmc/core/sd_ops.h @@ -21,6 +21,7 @@ int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca); int mmc_app_send_scr(struct mmc_card *card); int mmc_app_sd_status(struct mmc_card *card, void *ssr); int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card); +int mmc_send_ext_addr(struct mmc_host *host, sector_t addr); #endif diff --git a/include/linux/mmc/sd.h b/include/linux/mmc/sd.h index 865cc0ca8543..af5fc70e09a2 100644 --- a/include/linux/mmc/sd.h +++ b/include/linux/mmc/sd.h @@ -15,6 +15,9 @@ #define SD_SEND_IF_COND 8 /* bcr [11:0] See below R7 */ #define SD_SWITCH_VOLTAGE 11 /* ac R1 */ +/* Class 2 */ +#define SD_ADDR_EXT 22 /* ac [5:0] R1 */ + /* class 10 */ #define SD_SWITCH 6 /* adtc [31:0] See below R1 */ From patchwork Sun Aug 25 07:41:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 822561 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (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 00B9517C64 for ; Sun, 25 Aug 2024 07:43:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724571810; cv=none; b=dx8WSVulkPsEbMHoQu6NFWZtWc0y4MkpDGs9k0l9gf2pAqUhqw+gOeUbSP2xUqqhynjIRdb7YAj7C8jdJ9uCdCgb8hGMM7z0zzaMiDllTSBxU9240uFRenqjepNlNM9f9AXvtW9zNQ4IYDsTycBS4FYCpI0BqFpP0RgEdH0ooQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724571810; c=relaxed/simple; bh=ZLyjzcUKugHnS1Slh2DK9RwpcyMhxM2y8sQJo0560PQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Xq9PQqNj26RG13UNca1LDMYq6lNYE+Zapq2JvtIemkytP59u0o+dfu0hmhjFkCPyyvRjvGA0+aHIXz5BodQGPhZUct+i6DPJc6v+X5fWx7epWbFEZCA7H3feGGV3nDRxtgzcsrhuY3VoQAlrYo0ekgnPoaqWuk0f/xNCTwKkZ7A= 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=V4Cbf5uU; arc=none smtp.client-ip=216.71.153.141 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="V4Cbf5uU" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1724571809; x=1756107809; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZLyjzcUKugHnS1Slh2DK9RwpcyMhxM2y8sQJo0560PQ=; b=V4Cbf5uUdfXmM3HVOwhPloNZnTH6FYX0p0sp5R6dBjPjLIT3KtLHlyiR LFnwOxBTP8szsZugnQJ1tZz7xBBh+B2Kh6EbUdxrufvZC6abZv3PAa9i3 zRDa0YWsg0glmO8vBF5Nv4y6HK6NdMXYu646Zdzffb5N6Z0IKR2y4ZUed 2crsUiLi7mmm4nc4pBYumNfMK+rtUJrJMvg/nz4EwWMxNF4r5DUjFbVdE Tns63KPjmIJtNaREGlZUmVkStbabQUWlpnUUVWMxJKvCuOObhYHeJUl9H OCma6tSErQCSVTxcs3AldvEOhcZwNT/APdaqG/dr/X0eKtVetDcsq4UBn A==; X-CSE-ConnectionGUID: +x/4owbORZiZJ96UfZIcBQ== X-CSE-MsgGUID: n1Ex2Hj2S/iqg3+fTIi9Tw== X-IronPort-AV: E=Sophos;i="6.10,175,1719849600"; d="scan'208";a="25100420" 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; 25 Aug 2024 15:43:28 +0800 IronPort-SDR: 66cad3e3_RpRV0AlzxoLaw03vSD+6dRLZ0LnneBxyPo4zl4YkLUeQvSj +EuFcJYsmQ2fPABwPVfYKEJFL3gA1MtxddtWscA== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Aug 2024 23:49:08 -0700 WDCIronportException: Internal Received: from avri-office.ad.shared (HELO avri-office.sdcorp.global.sandisk.com) ([10.45.31.142]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Aug 2024 00:43:26 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Adrian Hunter , Ricky WU , Avri Altman Subject: [PATCH v4 3/9] mmc: core: Add open-ended Ext memory addressing Date: Sun, 25 Aug 2024 10:41:35 +0300 Message-Id: <20240825074141.3171549-4-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240825074141.3171549-1-avri.altman@wdc.com> References: <20240825074141.3171549-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. Tested-by: Ricky WU 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 2c9963248fcb..8816b3f0a312 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_ult_capacity(card)) { + mmc_blk_wait_for_idle(mq, card->host); + mmc_send_ext_addr(card->host, blk_rq_pos(req)); } } From patchwork Sun Aug 25 07:41:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 822417 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (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 7DC2417C64 for ; Sun, 25 Aug 2024 07:43:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724571813; cv=none; b=F8lGB5C83aP7j9//p1dkcMiXd3MDZPv2lIN62jQigbGxUAEJVvxdtewawcM7EG3uaL83/xlo/Z4ZeWJxdHhkpxEUG0DIB7gdrahZhFk6sow/J1ZjeqnCpZss86LRDcsxtYI42V5OpVKBkzBvr4QZVOA+e3+KtaVTyDNiDWe09V4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724571813; c=relaxed/simple; bh=tLvWTxXXb5aqpxy15nYWZnF6mArThXUomPGalcDLJhM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tLEuMpG+Pnek9KVr2OycpSDiWYzMCdfFxdd2glUXP4xfqjCQJsHxXGq4PCT2rhihPShlPcGPuMDJJHOL5K24yVUCJhSdejonFMEU9gzGw+TKTmaNWv111dfDbBQ71qQNLhnIkS/g7u+58xE2DzSyVn7y3t01kvqgkoXpnj8T1e0= 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=d0j3C61j; arc=none smtp.client-ip=216.71.153.141 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="d0j3C61j" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1724571812; x=1756107812; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tLvWTxXXb5aqpxy15nYWZnF6mArThXUomPGalcDLJhM=; b=d0j3C61jzLoJ1ht8syt3DeUW4h6NS+csviw4hPN9ckpLXuexRgt+oSwX 5CPmjegITrn2sE506LariklRZVTvxGAMuOIIoXYNWxHKtlxLImgvIIFL1 Xk8621PPbGU32JWngTkgRYZBjbU09Kqliw6AS6ZMNVgs0OoDEIkD/UtBe eeWUfQnnDelF7YwOZFAN9veeFUv5sUHUH+Onf6KvocWlQHG7l6XsyaHs3 T7xnPpElBCBg/rE0GGnjVhlYXlHIaFn6tQUOuZTNPdHMDngRWQMOlF7nS 6nQTb7EpeUu8FQXP9c7rdAAv/RNRfUM5mt8r1rNFTH0sWiREjmiP13gcG w==; X-CSE-ConnectionGUID: TWyHE0giQ82DOWWD60rOAQ== X-CSE-MsgGUID: 0sumpg9sR8yCIjzXIY7mGw== X-IronPort-AV: E=Sophos;i="6.10,175,1719849600"; d="scan'208";a="25100425" 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; 25 Aug 2024 15:43:31 +0800 IronPort-SDR: 66cad3e7_+jLgpkhuKT9cbSLRkYqCZxhLHOxD359upoQueRyzz4wYjtY b4DlXBh4YgA5JY+6fj7dwoe9GjvQgtQCnhlIfUA== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Aug 2024 23:49:11 -0700 WDCIronportException: Internal Received: from avri-office.ad.shared (HELO avri-office.sdcorp.global.sandisk.com) ([10.45.31.142]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Aug 2024 00:43:30 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Adrian Hunter , Ricky WU , Avri Altman Subject: [PATCH v4 4/9] mmc: core: Add close-ended Ext memory addressing Date: Sun, 25 Aug 2024 10:41:36 +0300 Message-Id: <20240825074141.3171549-5-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240825074141.3171549-1-avri.altman@wdc.com> References: <20240825074141.3171549-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. Tested-by: Ricky WU Signed-off-by: Avri Altman --- drivers/mmc/core/block.c | 7 +++++++ drivers/mmc/core/core.c | 18 ++++++++++++++++++ drivers/mmc/core/queue.h | 1 + include/linux/mmc/core.h | 1 + 4 files changed, 27 insertions(+) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 8816b3f0a312..7020a568fb79 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_ult_capacity(card)) { + 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_ult_capacity(card)) { 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..4808e42d7855 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 || diff --git a/drivers/mmc/core/queue.h b/drivers/mmc/core/queue.h index 1498840a4ea0..7e191d7f0461 100644 --- a/drivers/mmc/core/queue.h +++ b/drivers/mmc/core/queue.h @@ -40,6 +40,7 @@ struct mmc_blk_ioc_data; struct mmc_blk_request { struct mmc_request mrq; struct mmc_command sbc; + struct mmc_command ext; struct mmc_command cmd; struct mmc_command stop; struct mmc_data data; diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h index 2c7928a50907..5560e70cb8d4 100644 --- a/include/linux/mmc/core.h +++ b/include/linux/mmc/core.h @@ -142,6 +142,7 @@ struct mmc_data { struct mmc_host; struct mmc_request { struct mmc_command *sbc; /* SET_BLOCK_COUNT for multiblock */ + struct mmc_command *ext; /* SD_ADDR_EXT for SDUC */ struct mmc_command *cmd; struct mmc_data *data; struct mmc_command *stop; From patchwork Sun Aug 25 07:41:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 822560 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (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 B11FDEDE for ; Sun, 25 Aug 2024 07:43:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724571817; cv=none; b=baxcVljQrMSU30EEQCGoe/OoYfJs6OOmZ0/jETtuRdunkkfQDEORuiEunbJfLBFIB8Q9RbzSUGfB3ijY6CBYyn6RYjqnO+GAJ9Vju+vuWRSv2GacfjgyBHrujchhExnH1/VTtT8GtQV0IqcHYWaKwjhoXpcV9w79/uncQhoKxUU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724571817; c=relaxed/simple; bh=XzWoprbPUJNm54nfwNUfNao74B+GBJ/I17Z5BydHUeA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qCZs81qp+VLZZprtCsiFCQxDuqIeXduY/U5IHtYy5Q0FH0gCDui+vEJTud1R7a9EBRjc8rvxYBFcPN4hDSideWUpCsJrNjp79dxmPzmp3JVMHZlhBWVjaAwif7rkaWaFyanK5uaaoBmOluYPddWbl7g5COW5H8Rtapu9WS3fjfE= 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=UD0rsPxI; arc=none smtp.client-ip=216.71.153.141 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="UD0rsPxI" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1724571816; x=1756107816; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XzWoprbPUJNm54nfwNUfNao74B+GBJ/I17Z5BydHUeA=; b=UD0rsPxIytbp9ykjmwrV6/y32wEtAacpavokyiFA+ibjlup/ynbXAELs 53NVQT6fVQnPrUBKOC7VqBbAizIoz+2pEJuBiL1KHtFtDOpWBLi/kFrFH 8dFhS+mWapX181ML5kIdZv7DpgwbLH5yHjPbU2bxbnjb5XVbimuw81B3r +fy7DsG3kxEF9fqryVzRxb2XlQMOzkbMxohWmTQo4GsZmgv3kPWt/37BK GrKzRPglwtbILo38MUGuUQIAhN+aEgGAfEz1isD35syO9uoPyf/ldzxdR d5UqLr0QzNvQOxyFFdQX4BCHHXezAqGRVsDGw/RKCGzZ+0C/xzYyuW672 w==; X-CSE-ConnectionGUID: q8ty/t3gQR+bnp8tZJ+ZvQ== X-CSE-MsgGUID: iPoNT7PuTWOYDCEys6ZWfA== X-IronPort-AV: E=Sophos;i="6.10,175,1719849600"; d="scan'208";a="25100432" 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; 25 Aug 2024 15:43:36 +0800 IronPort-SDR: 66cad3eb_Pk/qfYgJu2TtmNO9kJXdlJ5fbUcG/aVUtsJQdL1bAo6t16E BfvTXb4n5E6VKqKjqxpa2sSbHXrHPZGlmAKaLsw== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Aug 2024 23:49:15 -0700 WDCIronportException: Internal Received: from avri-office.ad.shared (HELO avri-office.sdcorp.global.sandisk.com) ([10.45.31.142]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Aug 2024 00:43:34 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Adrian Hunter , Ricky WU , Avri Altman Subject: [PATCH v4 5/9] mmc: host: Always use manual-cmd23 in SDUC Date: Sun, 25 Aug 2024 10:41:37 +0300 Message-Id: <20240825074141.3171549-6-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240825074141.3171549-1-avri.altman@wdc.com> References: <20240825074141.3171549-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 Multi-Block read/write, CMD23 must precede CMD22. Therefore always use manual cmd23 so that we'll be able to control the sequence of commands. Also, add an applicable mmc_command member for both mmc_blk_request and mmc_request to accommodate the address extension command. Tested-by: Ricky WU Signed-off-by: Avri Altman --- drivers/mmc/host/sdhci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 4b91c9e96635..f62b489c9e9c 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -1399,13 +1399,13 @@ static inline bool sdhci_auto_cmd12(struct sdhci_host *host, static inline bool sdhci_auto_cmd23(struct sdhci_host *host, struct mmc_request *mrq) { - return mrq->sbc && (host->flags & SDHCI_AUTO_CMD23); + return mrq->sbc && (host->flags & SDHCI_AUTO_CMD23) && !mrq->ext; } static inline bool sdhci_manual_cmd23(struct sdhci_host *host, struct mmc_request *mrq) { - return mrq->sbc && !(host->flags & SDHCI_AUTO_CMD23); + return mrq->sbc && (mrq->ext || !(host->flags & SDHCI_AUTO_CMD23)); } static inline void sdhci_auto_cmd_select(struct sdhci_host *host, From patchwork Sun Aug 25 07:41:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 822416 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (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 82CAFEDE for ; Sun, 25 Aug 2024 07:43:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724571820; cv=none; b=c6xxOJxNkdUkHO49gl3v4g5NZ7ylRwQ2ykhMy98egJgyGmZjuBzyWdSQwEib/qSHV38POF/FjTdqT9e57PcMFY/SO4iLQlCnXy9G+6PAuXlgVq5kdCkoC9b8QS/hbPZXQAvFqJ0++AlNsH4iYKokZ7a148ud/sbnw5UIKbJiQXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724571820; c=relaxed/simple; bh=p4mm+jRORols3uszoL5zcbC2+6C+0onRtRnaw9DzQHE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Sfxtrgnx4M6pdj7+F5wgNgTsmMt3C7SdXQq/MxetqMWWze/ChXyFx3KTqSPegBNeOjgG1uuWR902ZyKkJ2paUEtKfoORU5O2WEtlIr1fz2B0femlSF1pNOPK3DaeDPntD00zgiBY7ubKAgs2vG5A1DCds0IOz+RqmJdJtnMV/Gk= 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=qBAIVDpl; arc=none smtp.client-ip=216.71.153.141 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="qBAIVDpl" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1724571820; x=1756107820; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=p4mm+jRORols3uszoL5zcbC2+6C+0onRtRnaw9DzQHE=; b=qBAIVDplz4GRlZSoZEI6RiHVgX9Skxd9v6GIZgkvPN6mYf2H7lksGHsU R9c75VaEaE7Myd6XGxfPz8wdHBS/C+rqOmUUDufih81/7yijuCeeqDR3p WUda9or9MsZcHsUzB+e5oWHT3wlv1bkyET2bxLvEU5tGKO5lotd+KVvVE zEvXpwgbmjZIxgQU+3U1RdFbflZCKsAc6C1RbVtuErIgQyO2F7xneXBcV fczTBMoSvUxW2abAO0F8QO6I5l20XnIMJ8zSMyoKR50k6Jj85n2KKAz/A J4jC9EY0osmpS1zSTKb1tQldvEl1mQJta8dCWVgk6GGlsIqHlTWQFOURg g==; X-CSE-ConnectionGUID: wCrv4p5CTvaup7hNP8Ey9A== X-CSE-MsgGUID: FTanwsgnTnWc6fjJFMSbPg== X-IronPort-AV: E=Sophos;i="6.10,175,1719849600"; d="scan'208";a="25100437" 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; 25 Aug 2024 15:43:39 +0800 IronPort-SDR: 66cad3ef_H8p3PXSmQNKM73xC5QqwGI+T6/UN3A6g1hoDkC0xU2DfjBf 5XEeZj8/ATIn2qRcmzl31pkVkZtPh6YmKdgskww== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Aug 2024 23:49:19 -0700 WDCIronportException: Internal Received: from avri-office.ad.shared (HELO avri-office.sdcorp.global.sandisk.com) ([10.45.31.142]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Aug 2024 00:43:38 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Adrian Hunter , Ricky WU , Avri Altman Subject: [PATCH v4 6/9] mmc: host: Add close-ended Ext memory addressing Date: Sun, 25 Aug 2024 10:41:38 +0300 Message-Id: <20240825074141.3171549-7-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240825074141.3171549-1-avri.altman@wdc.com> References: <20240825074141.3171549-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 close-ended multi-block data transfer, CMD23 shall precede CMD22. Handle that logic once the sbc is done. Host drivers that handle their own sbc logic, e.g. bcm2835 etc. are out of scope of this change. Tested-by: Ricky WU Signed-off-by: Avri Altman --- drivers/mmc/host/sdhci.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index f62b489c9e9c..70c967029fe3 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -1791,9 +1791,38 @@ static void sdhci_read_rsp_136(struct sdhci_host *host, struct mmc_command *cmd) } } +static struct mmc_command *sdhci_get_sbc_ext(struct sdhci_host *host, + struct mmc_command *cmd) +{ + bool is_sduc = mmc_card_ult_capacity(host->mmc->card); + + if (is_sduc) { + /* Finished CMD22, now send actual command */ + if (cmd == cmd->mrq->ext) + return cmd->mrq->cmd; + } + + /* Finished CMD23 */ + if (cmd == cmd->mrq->sbc) { + if (is_sduc) { + /* send CMD22 after CMD23 */ + if (WARN_ON(!cmd->mrq->ext)) + return NULL; + else + return cmd->mrq->ext; + } else { + /* Finished CMD23, now send actual command */ + return cmd->mrq->cmd; + } + } + + return NULL; +} + static void sdhci_finish_command(struct sdhci_host *host) { struct mmc_command *cmd = host->cmd; + struct mmc_command *sbc_ext = NULL; host->cmd = NULL; @@ -1828,14 +1857,13 @@ static void sdhci_finish_command(struct sdhci_host *host) } } - /* Finished CMD23, now send actual command. */ - if (cmd == cmd->mrq->sbc) { - if (!sdhci_send_command(host, cmd->mrq->cmd)) { + sbc_ext = sdhci_get_sbc_ext(host, cmd); + if (sbc_ext) { + if (!sdhci_send_command(host, sbc_ext)) { WARN_ON(host->deferred_cmd); host->deferred_cmd = cmd->mrq->cmd; } } else { - /* Processed actual command. */ if (host->data && host->data_early) sdhci_finish_data(host); From patchwork Sun Aug 25 07:41:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 822559 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (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 232F8EDE for ; Sun, 25 Aug 2024 07:43:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724571825; cv=none; b=TVonl8WLo+vxMqJRboT9SQOHRoLlndiyjlN/VlyyxnBy3jRPrKnGZLIjeSxgQjnTT6zZxLKrCv2wSLv4z7hzAUkPwoXaf0P4BE9NGJyy0Qsgaqu2J+uqeFAzcaqcgD9WdzlBj4GsGa8S9st0kM+BX0Y+jV4R2O//XpLohoad4mo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724571825; c=relaxed/simple; bh=tB3JP7FQXiGBkA31WdsdzyYj4BGqT5d6ySH0NxMliKY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZkcaAgDhtk/gz3Xmc8ikTIuRhBw/V1KAHzWWywZf+0mg3KJ7nI2parvG4NB+M8L8jZ7M2U5JS7KHebmkQnq5fyfNaQrUelWstU/85NftX9ZwMzmgqmc1ToEPZE2b3iU2Ca0a/BGgykbwfo1xl7tFE0EImYL7+cSHSNkL+Z+yv2U= 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=nCwrHGcg; arc=none smtp.client-ip=216.71.153.141 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="nCwrHGcg" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1724571824; x=1756107824; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tB3JP7FQXiGBkA31WdsdzyYj4BGqT5d6ySH0NxMliKY=; b=nCwrHGcggn4dFLSPRXhodsAol9pW5ixoxRd4Mc3zzWsVGp8I0EUUJV9+ q1YfhPYc8vm0jycQlSQpdyYGNfn5nw5EuSu7teCMB6kj9DcnM784lRktS IOOcg49cfqgByGDNoYZ19UtlDUQUchCuo0/HhGWLYC0VH+gEIvx/95cJw de/ILgYjo+xhpD6KZWqsY+2kHQZum5FvK5mhIlWVGLYEW/o6HggPz5B5O +JqaAgR39ko7xI7GBdUAdnR3le6J7mPTsizMV7yqT21zo4gfzdHefl8lT Ng1mbbOFdtEBHXVqS4xkSy2U1woGnK2Pmrs9bcaRoRcFsN0EQbhJVubu3 Q==; X-CSE-ConnectionGUID: ABDNlZTGSPu/J6wrUp6aAw== X-CSE-MsgGUID: yg0yEgziRN2hr6qr9VfRSg== X-IronPort-AV: E=Sophos;i="6.10,175,1719849600"; d="scan'208";a="25100443" 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; 25 Aug 2024 15:43:44 +0800 IronPort-SDR: 66cad3f3_UeGRm+9TUkaC7E1DUKlIwUuwCq7I4wOOnHEYRJdQkeEg2za L3veRP2M/E5XDxsmg2qnG1bz53XgIuePVoQxwaQ== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Aug 2024 23:49:24 -0700 WDCIronportException: Internal Received: from avri-office.ad.shared (HELO avri-office.sdcorp.global.sandisk.com) ([10.45.31.142]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Aug 2024 00:43:42 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Adrian Hunter , Ricky WU , Avri Altman Subject: [PATCH v4 7/9] mmc: core: Allow mmc erase to carry large addresses Date: Sun, 25 Aug 2024 10:41:39 +0300 Message-Id: <20240825074141.3171549-8-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240825074141.3171549-1-avri.altman@wdc.com> References: <20240825074141.3171549-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. Tested-by: Ricky WU Signed-off-by: Avri Altman --- drivers/mmc/core/block.c | 6 ++++-- drivers/mmc/core/core.c | 33 ++++++++++++++++++--------------- drivers/mmc/core/core.h | 16 ++++++++++++---- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 7020a568fb79..ace701273230 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 4808e42d7855..2148ce4535ee 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; @@ -1648,8 +1648,8 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from, else if (mmc_card_sd(card)) qty += to - from + 1; else - qty += ((to / card->erase_size) - - (from / card->erase_size)) + 1; + qty += (mmc_sector_div(to, card->erase_size) - + mmc_sector_div(from, card->erase_size)) + 1; if (!mmc_card_blockaddr(card)) { from <<= 9; @@ -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; @@ -1741,7 +1742,7 @@ static unsigned int mmc_align_erase_size(struct mmc_card *card, nr_new = round_down(nr_new, card->erase_size); } else { - rem = from_new % card->erase_size; + rem = mmc_sector_mod(from_new, card->erase_size); if (rem) { rem = card->erase_size - rem; from_new += rem; @@ -1774,10 +1775,12 @@ 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)) @@ -1798,7 +1801,7 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr, return -EOPNOTSUPP; if (arg == MMC_SECURE_ERASE_ARG) { - if (from % card->erase_size || nr % card->erase_size) + if (mmc_sector_mod(from, card->erase_size) || nr % card->erase_size) return -EINVAL; } @@ -1822,7 +1825,7 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr, * and call mmc_do_erase() twice if necessary. This special case is * identified by the card->eg_boundary flag. */ - rem = card->erase_size - (from % card->erase_size); + rem = card->erase_size - mmc_sector_mod(from, card->erase_size); if ((arg & MMC_TRIM_OR_DISCARD_ARGS) && card->eg_boundary && nr > rem) { err = mmc_do_erase(card, from, from + rem - 1, arg); from += rem; @@ -1881,12 +1884,12 @@ int mmc_can_secure_erase_trim(struct mmc_card *card) } EXPORT_SYMBOL(mmc_can_secure_erase_trim); -int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from, +int mmc_erase_group_aligned(struct mmc_card *card, sector_t from, unsigned int nr) { if (!card->erase_size) return 0; - if (from % card->erase_size || nr % card->erase_size) + if (mmc_sector_mod(from, card->erase_size) || nr % card->erase_size) return 0; return 1; } diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h index 37091a6589ed..fc9d5e9620b1 100644 --- a/drivers/mmc/core/core.h +++ b/drivers/mmc/core/core.h @@ -116,15 +116,13 @@ 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, - unsigned int arg); +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); int mmc_can_discard(struct mmc_card *card); int mmc_can_sanitize(struct mmc_card *card); int mmc_can_secure_erase_trim(struct mmc_card *card); -int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from, - unsigned int nr); +int mmc_erase_group_aligned(struct mmc_card *card, sector_t from, unsigned int nr); unsigned int mmc_calc_max_discard(struct mmc_card *card); int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen); @@ -199,4 +197,14 @@ static inline int mmc_flush_cache(struct mmc_host *host) return 0; } +static inline unsigned int mmc_sector_div(sector_t dividend, u32 divisor) +{ + return div_u64(dividend, divisor); +} + +static inline unsigned int mmc_sector_mod(sector_t dividend, u32 divisor) +{ + return sector_div(dividend, divisor); +} + #endif From patchwork Sun Aug 25 07:41:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 822415 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (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 87123EDE for ; Sun, 25 Aug 2024 07:43:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724571829; cv=none; b=mEdUgkzs4yRK0F/S+qG1EcGr1AOIROdoEDKCmQVFFdEHCsaQAlRhXxEASpX5Un/5nGWb9HdsK3BBNBMikCIWTxdpoc8LeOr6W+M6NWTomvnhnUMWyep4K126fnEjdTEiW+WsyRHltHCFD0pYt2JlnSE3MXbwSJGPOCLHYSitUtw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724571829; c=relaxed/simple; bh=IH8LiC8RXqEYWeE5wiX6U/jl2mWswK2gnyJUfS5YXxc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EfdxqHaauYBgr5BjMcGoHl3pTW8akEyJqsTRqsSvoje7AgJ8Gu7xjeIMbWEE4dwfmiHNUv9IvdN0iSwjJaG6SpHrgkRusrt/wXqY8Rtt8r9ipKWJ+a+m8SFoWlRvZu8Bbo8eV3+wDlshWTvXNEA6tJLkvGV/Sd+htFTVUZqca5c= 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=dPVzMRje; arc=none smtp.client-ip=216.71.153.141 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="dPVzMRje" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1724571828; x=1756107828; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IH8LiC8RXqEYWeE5wiX6U/jl2mWswK2gnyJUfS5YXxc=; b=dPVzMRje5oVeCmrd4oxEFwlL4PGv19l48gsRQ5t2xbaJq8EtNqyaFTid fAmOo4dA94Qx8jXexramc9jo/mE55lM3wRe3Tn8DUDrlPlV3Jtaw0Si8s 7kGYWFDS/ThNQtXO/owvAF4+n4mj6CmGomCTgveLQHjdCBUe/+G7+30YR xo9FeHEIzw9XABQKBvXWywlwlLsGhUee/yAyWHYMJ8ow6+K/Sz2irczoi 2MYtEAP2AsdsRjW3P0Cq8Nl/TV0gd0qp6dalxQeCgRutZFZvXNxT9bI3o lJ/sCx6H4ua8ksKSpqaaucSnIlwdfGLSpKvdXqd8ACtgL2BK8FYRr88aw w==; X-CSE-ConnectionGUID: m+wQO0k/TkilwHoC8iUOnw== X-CSE-MsgGUID: wq2C8LEtRYmKH0UNhCG+ow== X-IronPort-AV: E=Sophos;i="6.10,175,1719849600"; d="scan'208";a="25100444" 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; 25 Aug 2024 15:43:47 +0800 IronPort-SDR: 66cad3f7_JEK5nUpSevJiwHBNiGKgW4CvoX4tEpQIKsCVPe8GBDKZiRk 5trGw+r1EjR6HqzBWi17k4Y2gTdhBeOWH92/4Sg== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Aug 2024 23:49:27 -0700 WDCIronportException: Internal Received: from avri-office.ad.shared (HELO avri-office.sdcorp.global.sandisk.com) ([10.45.31.142]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Aug 2024 00:43:46 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Adrian Hunter , Ricky WU , Avri Altman Subject: [PATCH v4 8/9] mmc: core: Add Ext memory addressing for erase Date: Sun, 25 Aug 2024 10:41:40 +0300 Message-Id: <20240825074141.3171549-9-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240825074141.3171549-1-avri.altman@wdc.com> References: <20240825074141.3171549-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 CMD22 shall precede CMD32 and CMD33 to configure 38-bit erase start address and 38 bit erase stop address. Tested-by: Ricky WU Signed-off-by: Avri Altman --- drivers/mmc/core/core.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 2148ce4535ee..3315c1fad264 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1660,8 +1660,12 @@ static int mmc_do_erase(struct mmc_card *card, sector_t from, cmd.opcode = SD_ERASE_WR_BLK_START; else cmd.opcode = MMC_ERASE_GROUP_START; - cmd.arg = from; + cmd.arg = from & 0xFFFFFFFF; cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC; + + if (mmc_card_ult_capacity(card)) + mmc_send_ext_addr(card->host, from); + err = mmc_wait_for_cmd(card->host, &cmd, 0); if (err) { pr_err("mmc_erase: group start error %d, " @@ -1675,8 +1679,12 @@ static int mmc_do_erase(struct mmc_card *card, sector_t from, cmd.opcode = SD_ERASE_WR_BLK_END; else cmd.opcode = MMC_ERASE_GROUP_END; - cmd.arg = to; + cmd.arg = to & 0xFFFFFFFF; cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC; + + if (mmc_card_ult_capacity(card)) + mmc_send_ext_addr(card->host, to); + err = mmc_wait_for_cmd(card->host, &cmd, 0); if (err) { pr_err("mmc_erase: group end error %d, status %#x\n", From patchwork Sun Aug 25 07:41:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 822558 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) (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 C80DBEDE for ; Sun, 25 Aug 2024 07:43:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.141.245 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724571841; cv=none; b=O/k49sBUpYOmWrDWrlCohJhAtdCmUMxCpzVF3jK1EFnEe7rl6lrF3y/fwoaWgu1wbRW+vvuYoOqt/uYMdWVV+Z2HcL+Dv7NHiRgYjvzyEuLcq2O3ho3G20p6idD53/Tj0TDGzEnPZwLFrK4ERvkKyUDuJMas1kF3X3fytOpNBFs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724571841; c=relaxed/simple; bh=eRGyXkRNf12FO5hnq5bGdZNbwuDfGdpNMqjWAsTwWJU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lpVgVDotJyCwU2RNOUr/03LKf2LNS5H9qxDPCumRmTRcQRQ03xJQM7Pyy3smipjQ1mcOXur0NpYuPNQPL3M2rgpys0bxkGJMmz7REfwW4IuL0SdILDIMXDHpesAKi78g+B6dR4ZPCEtGa6JY5bxpJ8lYg7Q/7HXpFbuwy/SDEVM= 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=oWUZQsgo; arc=none smtp.client-ip=68.232.141.245 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="oWUZQsgo" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1724571839; x=1756107839; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eRGyXkRNf12FO5hnq5bGdZNbwuDfGdpNMqjWAsTwWJU=; b=oWUZQsgoHZeFcb6GyB1UuI8eOmgFccyfJECG1lXJqnsDHYV1yX2/dsMp xgnEZ00DWNk5mcRs6Cm3WulpwfQbOcBarxHBKVAALOMv54OTP9fDAdEcJ Qsjvx/QzdAfruMuzs5P24wWWl8va/TaEe6jRZncIKL/DaTWvIXYN65/t6 huOJSGLxCUG+hMpjhKR/toshOVYpWDoonH6y2tyQ/ZbVUElxY6aYNpvS0 +IZcSoQs/DMEZiio17aHr+rumQnRPLWpBJLW2kExEYKfjbKmX+ePYtb/q 8eu5qCnkDCy09eo9QocZ4jtf1Sdmq96yCBNZUpZtIZ4S2EOqMj6MSDwqe A==; X-CSE-ConnectionGUID: 6pun1QaFTgWp5ZwdK/OhfQ== X-CSE-MsgGUID: 5C6POaX4RCake3j+3U0bLA== X-IronPort-AV: E=Sophos;i="6.10,175,1719849600"; d="scan'208";a="25888393" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 25 Aug 2024 15:43:52 +0800 IronPort-SDR: 66cad2a8_0EjwyK4bnOuNR0QD/D/c7hGu5Uuey7Qk85K2m2l01lyZHe2 94SlPg7SstmDfC0RClo3YrRn/xSqMSFV0SnWTbw== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 24 Aug 2024 23:43:53 -0700 WDCIronportException: Internal Received: from avri-office.ad.shared (HELO avri-office.sdcorp.global.sandisk.com) ([10.45.31.142]) by uls-op-cesaip01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Aug 2024 00:43:51 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Adrian Hunter , Ricky WU , Avri Altman Subject: [PATCH v4 9/9] mmc: core: Adjust ACMD22 to SDUC Date: Sun, 25 Aug 2024 10:41:41 +0300 Message-Id: <20240825074141.3171549-10-avri.altman@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240825074141.3171549-1-avri.altman@wdc.com> References: <20240825074141.3171549-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 not a superfluous requirement, because SDUC writes may exceeds 2TB. For Linux mmc however, the previously write operation could not be more than the block layer limits, thus we make room for a u64 and cast the returning value to u32. 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 | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index ace701273230..b73fdef1cb0d 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -48,6 +48,7 @@ #include #include +#include #include "queue.h" #include "block.h" @@ -948,13 +949,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_ult_capacity(card)) + mmc_delay(500); + err = mmc_app_cmd(card->host, card); if (err) return err; @@ -963,7 +971,14 @@ 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 not a superfluous + * requirement, because SDUC writes may exceed 2TB. + */ + resp_sz = mmc_card_ult_capacity(card) ? 8 : 4; + + data.blksz = resp_sz; data.blocks = 1; data.flags = MMC_DATA_READ; data.sg = &sg; @@ -973,15 +988,25 @@ 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); - result = ntohl(*blocks); + if (mmc_card_ult_capacity(card)) { + u64 blocks_64 = get_unaligned_be64(blocks); + /* + * For Linux mmc however, the previously write operation could + * not be more than the block layer limits, thus just make room + * for a u64 and cast the response back to u32. + */ + result = blocks_64 > UINT_MAX ? UINT_MAX : (u32)blocks_64; + } else { + result = ntohl(*blocks); + } kfree(blocks); if (cmd.error || data.error)