From patchwork Wed Oct 19 08:21:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4554 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp204531wrs; Wed, 19 Oct 2022 01:46:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6NSMhn+lczhS//kTQ/ohyHZfEN4mCAol4rtpENTNjBmPX8QOmvfyA70OxE5Rss2kNhMsfa X-Received: by 2002:a17:90a:f3ca:b0:20a:d4ee:3859 with SMTP id ha10-20020a17090af3ca00b0020ad4ee3859mr8643488pjb.70.1666169185411; Wed, 19 Oct 2022 01:46:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666169185; cv=none; d=google.com; s=arc-20160816; b=lEc94D2q9HoQaJJLMxZ/WfESY1JgX3ycqJBJvR2NlkZm0ps1+Hy40NN3vt9kpO/EM5 Bh7R7hp7hfqyaVRLKB72L5mS3lDN2e1fqTPTtaEM3dHZLAhtp4r2qW0WuWd0smxFf/wb +5IQBxz1CTIAWJZAtVhWOkdABrvsKcJdKdnNUTgBOZO4WVJ98D8JhphjvvXiIt+Pk8Ia Gt0/hhWsCHwRzew+QXFCngZGkny3XLSY5mTANNv4hT32/Bj7uM5f3KniXCztCAxNRc0J ZJ+/Be+pOZ9aXmIe70WlSgOSuFe4tnI/XsydEE7q7koI66sD3L1Vt4mB/XGzgH2z1H9o 4BPw== 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=szg3zva8xluSXotCoi5UXUU2f4N/N+Q990n1a2uu0cc=; b=egM/iNNeKeh141183ql56ZQTnxIpySNHNfiq4l1AmmUZuwWHu5aPApAz4e4n1Nsw8q hbCGXEtiWoec1LMWCKZYSDiIspGhVXFAqwpdos93GLihxLg1wKpu+drxRwcr0cg/k4GT /WOvXkML/VbCowixhcqpvv8MYW8XzTiKv04nV2LwUTLpRwO1iFcU/+3+I41/Y92srWgb 0CU2C91d58jUga0XP3wqcK+EmoNuIdOFGYnAXlwg0TmYNJNqC55qX6PW/vVBLMpvlKA4 +33Aiql9Ev4MGrZ4okNQi719Sh+Qtrkx57kpONjNVjhq8y9uMwwwye6mZ5h6K/CGS6ir FbVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hGYWIWDj; 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 184-20020a6302c1000000b004607161e35dsi17321179pgc.830.2022.10.19.01.46.12; Wed, 19 Oct 2022 01:46:25 -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=hGYWIWDj; 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 S231314AbiJSIpe (ORCPT + 99 others); Wed, 19 Oct 2022 04:45:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231362AbiJSIoC (ORCPT ); Wed, 19 Oct 2022 04:44:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CB27578BE; Wed, 19 Oct 2022 01:42:00 -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 087D7617EC; Wed, 19 Oct 2022 08:40:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D2C6C433C1; Wed, 19 Oct 2022 08:40:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666168835; bh=AO6bebF1z40eus5tkLpFMLiEY8a5u2OEABA+TuAC3ug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hGYWIWDji7qWaKo49jo/yO9R1mPm4zHT6P8ZILihSfmi/e7ad+4pw8k3+X+EeTKik B4UM+KwSXu01cIfYaYpowk+BJgGFJzwBuTjN2XuJwNmPi0KZp8ukkjwvWrEljN8ujp 8LwOkYDp55ATmmjPG1sX+E7rCIEVm+a1HYSNz9Xg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Avri Altman , Ulf Hansson Subject: [PATCH 6.0 032/862] mmc: core: Add SD card quirk for broken discard Date: Wed, 19 Oct 2022 10:21:59 +0200 Message-Id: <20221019083251.438437419@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747105019720421825?= X-GMAIL-MSGID: =?utf-8?q?1747105019720421825?= 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 @@ -293,6 +293,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 */