From patchwork Sat Oct 22 07:18:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7148 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1087728wrr; Sat, 22 Oct 2022 00:37:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6WXk0KMBw5/5huF0+7qcpo1bZr5LcWKW7QReOA5KQCszcj3d8pr4clFgzg5a70oafMKFgm X-Received: by 2002:a63:fa4d:0:b0:43c:7fa:95f7 with SMTP id g13-20020a63fa4d000000b0043c07fa95f7mr19186001pgk.48.1666424249385; Sat, 22 Oct 2022 00:37:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666424249; cv=none; d=google.com; s=arc-20160816; b=FqEQsSR4h8t6w1osiF6KdTvHBhdMEM9KVLOART/qPH+C9crVzQRPbEsZlikBgZS9RY ycFmxGTRnWjq9ooUNBuGFWIrC2QAa9vC78RupXtV8dU8nkDhT0Mxtq2KM95AhcrcLCj0 bBeq1rXd7XhXhY2+wCZifNF4CRkiHnp/EUHVlNSusltpz8OVFGjQ+0tTEI1MQf7VsBJU 3No1hkjxsL+RcIALIrGJdvyHWwx1hZh2CI2oupWFHev9SocrGbvfJ64R7OYEfj7OkKN4 9KRuCJrgZiGbCcEo2gbnuYrVrvZgevec0fOzJMdcL9/RNY2liuapWW3WbOpNwLrueqG2 1Wsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3Ria8PZQ6eYLTv5p9jKfpoIDY4A4qRlSn88ua++31EY=; b=n5R/wD0AQGrsCU5vU5i0KDc5sc916+8HEukFGJE7/YcmOaI8G8kHVXa9jlr1TFi/YG 0p3htPqR0gjpfdZElYkX62t+TR+DXYh/SiygABQjS9ewFtY63qZJX8q51Qp/l1yLLacG KsT5cEkbOEHu9vJSp08DvmPpLe96ROb+FxYhJoF9axokQDU5pa7i7i4IPxUFoTg774dD fPlOmRYmJ4DE1ayDIwOv6kRq+nieOVJ6uAAqJgNx75iv+iYlgYwHi9jm+CNgyAZ0cyO+ 2UPBnjpd8FGH7SS6zzQmFJeUFOe2Yrj14VM67QMBYf2nV+GxVMqgo9JFsPm4kODHYyYf y7yQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aS5hFWag; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n9-20020a170902f60900b0017f73e4af01si11598970plg.298.2022.10.22.00.37.16; Sat, 22 Oct 2022 00:37:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aS5hFWag; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230218AbiJVHgg (ORCPT + 99 others); Sat, 22 Oct 2022 03:36:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230146AbiJVHfk (ORCPT ); Sat, 22 Oct 2022 03:35:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB60863F24; Sat, 22 Oct 2022 00:34:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8741260ADB; Sat, 22 Oct 2022 07:34:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B7E9C433D6; Sat, 22 Oct 2022 07:34:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424099; bh=RfWcLuhdM/efK7GPaA8Whk+57q1ge3rUrqp2Fx8g4os=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aS5hFWagyT8on5QN0N/lmc1vtAkPjc93kdPahL1JWrEy9r2rEZ2GMTI1g5U0yoV9P Mm/v3ylSySTPgReR4bhE1Zz7sYoiynLPRmBV3oDoEysSGaaNKPIhN+z0YZphP4qL62 rokg/hadZfzC1+u1VRQ1Xh+1Q+Y5GdgurqPUkDiM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Avri Altman , Ulf Hansson Subject: [PATCH 5.19 027/717] mmc: core: Add SD card quirk for broken discard Date: Sat, 22 Oct 2022 09:18:26 +0200 Message-Id: <20221022072419.914374623@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747372473789018712?= X-GMAIL-MSGID: =?utf-8?q?1747372473789018712?= From: Avri Altman commit 07d2872bf4c864eb83d034263c155746a2fb7a3b upstream. Some SD-cards from Sandisk that are SDA-6.0 compliant reports they supports discard, while they actually don't. This might cause mk2fs to fail while trying to format the card and revert it to a read-only mode. To fix this problem, let's add a card quirk (MMC_QUIRK_BROKEN_SD_DISCARD) to indicate that we shall fall-back to use the legacy erase command instead. Signed-off-by: Avri Altman Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20220928095744.16455-1-avri.altman@wdc.com [Ulf: Updated the commit message] Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/core/block.c | 6 +++++- drivers/mmc/core/card.h | 6 ++++++ drivers/mmc/core/quirks.h | 6 ++++++ include/linux/mmc/card.h | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -1140,8 +1140,12 @@ static void mmc_blk_issue_discard_rq(str { struct mmc_blk_data *md = mq->blkdata; struct mmc_card *card = md->queue.card; + unsigned int arg = card->erase_arg; - mmc_blk_issue_erase_rq(mq, req, MMC_BLK_DISCARD, card->erase_arg); + if (mmc_card_broken_sd_discard(card)) + arg = SD_ERASE_ARG; + + mmc_blk_issue_erase_rq(mq, req, MMC_BLK_DISCARD, arg); } static void mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq, --- a/drivers/mmc/core/card.h +++ b/drivers/mmc/core/card.h @@ -73,6 +73,7 @@ struct mmc_fixup { #define EXT_CSD_REV_ANY (-1u) #define CID_MANFID_SANDISK 0x2 +#define CID_MANFID_SANDISK_SD 0x3 #define CID_MANFID_ATP 0x9 #define CID_MANFID_TOSHIBA 0x11 #define CID_MANFID_MICRON 0x13 @@ -258,4 +259,9 @@ static inline int mmc_card_broken_hpi(co return c->quirks & MMC_QUIRK_BROKEN_HPI; } +static inline int mmc_card_broken_sd_discard(const struct mmc_card *c) +{ + return c->quirks & MMC_QUIRK_BROKEN_SD_DISCARD; +} + #endif --- a/drivers/mmc/core/quirks.h +++ b/drivers/mmc/core/quirks.h @@ -100,6 +100,12 @@ static const struct mmc_fixup __maybe_un MMC_FIXUP("V10016", CID_MANFID_KINGSTON, CID_OEMID_ANY, add_quirk_mmc, MMC_QUIRK_TRIM_BROKEN), + /* + * Some SD cards reports discard support while they don't + */ + MMC_FIXUP(CID_NAME_ANY, CID_MANFID_SANDISK_SD, 0x5344, add_quirk_sd, + MMC_QUIRK_BROKEN_SD_DISCARD), + END_FIXUP }; --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -292,6 +292,7 @@ struct mmc_card { #define MMC_QUIRK_BROKEN_IRQ_POLLING (1<<11) /* Polling SDIO_CCCR_INTx could create a fake interrupt */ #define MMC_QUIRK_TRIM_BROKEN (1<<12) /* Skip trim */ #define MMC_QUIRK_BROKEN_HPI (1<<13) /* Disable broken HPI support */ +#define MMC_QUIRK_BROKEN_SD_DISCARD (1<<14) /* Disable broken SD discard support */ bool reenable_cmdq; /* Re-enable Command Queue */