Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1399377pxb; Mon, 22 Feb 2021 00:17:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJzCJcVXbQrL0etNAt+z6LwiLDQq5bpLKMfPQJWChO1M1szdFjIspHuqidIVl204s44Ruzqr X-Received: by 2002:a05:6402:893:: with SMTP id e19mr11761477edy.206.1613981871071; Mon, 22 Feb 2021 00:17:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613981871; cv=none; d=google.com; s=arc-20160816; b=MoMTYPrXokAuoAz2dQV+6zVIir9kg5gtMP5MicYar8ZSr30zCULUXdcbI3MUgXIxH/ X3GCUIZ2Ip6cqdELZ7yCX6eBciz107IopQnfnF4OzUCSyio7lXmznLfE7N4pIB1yrdwn rOmGCNXfmWNspBwreVp1Aml/uKa/AZuzI4F6KTUhvPIMsvTF1RQ4bxcpWDkDGlKLk88n H+g1VN8ibZULeSjPtyv4UMSixsrSwXFAMzUkG3vSbCMjd4Pe/h+Vb5FBKGzz1fE9u4p/ RfjSQftiwXb+pzEs5NeLJStDh44EBTdUXCn3mNb1AKJbQbR+J1qjsLBqh7lVnRIcFqoo gdVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:dlp-filter:cms-type :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature:dkim-filter; bh=YoUlv36H2rILg+JTXk1la+doFVImFBaKXU7o06vDG50=; b=DFb2ScjU2DWXZeuuRKsZ6uDg4+VwX87JvxuWBEJg+eOb54K2mw+HqVlPM4utaK3Sqo jTuuZnNs3AYp92RtiP3klel8/lJ7laMJpTEuqBSVgSd8mUMTGKmEKWV+AnlYC8pEE0QM vgq+2wqjaZ1OyKPObJnP9/VgGu7dO/3jnmAj2BW2xbrPjiYm17Ld4cIympZHMNe8Qm4d VSaqiQ1iDybsWRNoh/PyBPGyQq0mGXXfeSGQ1nL8iEwbRCkwwJ3CDR0s6otP6iEAxJi+ Ee2GJZxcLUTpAzUpUMUNOy6CLZPbV12XFbHtbmiurI9/5zPdoK1NXX/Y6opvsZ/7A6NM br1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=gIfpll40; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kl16si12057645ejc.565.2021.02.22.00.17.28; Mon, 22 Feb 2021 00:17:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=gIfpll40; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230022AbhBVIQE (ORCPT + 99 others); Mon, 22 Feb 2021 03:16:04 -0500 Received: from mailout3.samsung.com ([203.254.224.33]:25636 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229990AbhBVIQC (ORCPT ); Mon, 22 Feb 2021 03:16:02 -0500 Received: from epcas1p2.samsung.com (unknown [182.195.41.46]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20210222081519epoutp03ae9c6eab1576251d0b167b1b459c720b~mA9KdXQCn0032100321epoutp03O for ; Mon, 22 Feb 2021 08:15:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20210222081519epoutp03ae9c6eab1576251d0b167b1b459c720b~mA9KdXQCn0032100321epoutp03O DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1613981719; bh=YoUlv36H2rILg+JTXk1la+doFVImFBaKXU7o06vDG50=; h=From:To:Cc:Subject:Date:References:From; b=gIfpll40eCjW4JJZit2vl8gUJA+zQL913SqqsExzznUGM7C/MpRtyPUA8P+oD1mNR fzwZo0LRnBTMwODCB0GzkzaAhkEgT7n3tBLhglGuLhpLFiAXuXbgx+aXAA84O/38me RFAjx4xxBIa11zl2mbJNA73Xo7b8leU4WBP7iLQ0= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas1p3.samsung.com (KnoxPortal) with ESMTP id 20210222081518epcas1p3dbf9ad9271838002cfeea1cde9379012~mA9JzY2j00598905989epcas1p3A; Mon, 22 Feb 2021 08:15:18 +0000 (GMT) Received: from epsmges1p4.samsung.com (unknown [182.195.40.159]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4DkZjx69vmz4x9QR; Mon, 22 Feb 2021 08:15:17 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p4.samsung.com (Symantec Messaging Gateway) with SMTP id DC.9D.10463.51863306; Mon, 22 Feb 2021 17:15:17 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p3.samsung.com (KnoxPortal) with ESMTPA id 20210222081517epcas1p37fef998684dc9eae0bcd2764a3f82fb1~mA9IVP9bm0598905989epcas1p31; Mon, 22 Feb 2021 08:15:17 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20210222081517epsmtrp27d655bb8c526952c3c5405340743680f~mA9ITYSJA0340803408epsmtrp2l; Mon, 22 Feb 2021 08:15:17 +0000 (GMT) X-AuditID: b6c32a38-f11ff700000028df-10-60336815c38a Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 75.F0.13470.51863306; Mon, 22 Feb 2021 17:15:17 +0900 (KST) Received: from localhost.localdomain (unknown [10.253.101.71]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20210222081516epsmtip20c6a4c6591c85c63e46cf5513b5fceae~mA9ICvqNU1132911329epsmtip2T; Mon, 22 Feb 2021 08:15:16 +0000 (GMT) From: Seunghui Lee To: ulf.hansson@linaro.org, pali@kernel.org, huyue2@yulong.com, tiantao6@hisilicon.com, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: grant.jung@samsung.com, jt77.jang@samsung.com, dh0421.hwang@samsung.com, junwoo80.lee@samsung.com, jangsub.yi@samsung.com, cw9316.lee@samsung.com, sh8267.baek@samsung.com, wkon.kim@samsung.com, Seunghui Lee Subject: [PATCH] mmc: core: set read only with permanent write protect Date: Mon, 22 Feb 2021 17:31:56 +0900 Message-Id: <20210222083156.19158-1-sh043.lee@samsung.com> X-Mailer: git-send-email 2.29.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrAJsWRmVeSWpSXmKPExsWy7bCmga5ohnGCwZ4eA4sZp9pYLfZdO8lu 8evvenaLPbPvMlt0bJ3MZLHj+Rl2i11/m5ksLu+aw2Zx5H8/o8WCPafZLJr+7GOxuHbmBKvF 6tf72C2Orw232HzpG4sDv8fjuRvZPTat6mTzuHNtD5tH35ZVjB6fN8l5bF2zmDmALSrHJiM1 MSW1SCE1Lzk/JTMv3VbJOzjeOd7UzMBQ19DSwlxJIS8xN9VWycUnQNctMwfoZCWFssScUqBQ QGJxsZK+nU1RfmlJqkJGfnGJrVJqQUpOgaFBgV5xYm5xaV66XnJ+rpWhgYGRKVBlQk5GY/d9 loJvHBXf/19naWCcw97FyMkhIWAicfDcQZYuRi4OIYEdjBL7jn+Gcj4xStx88Y0NwvnGKDFx +1Y2mJa1q5sZIRJ7GSXOPVzLDOF8ZpS4suQi2GA2AS2J6Zu2MIEkRAQmM0osO7kYbDC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wzmHvYuTkkBAwkVi7upmxi5GLQ0hgN6PE5dlLWSAS khKLHz1k62LkALKFJQ4fLoao+cgoMeP2YbBmNgEtiembtjCBJEQEZjJK7Fp2lR3EYRb4xSix Y+oyNpAqYQE3iQd9y8FsFgFVicuPp7KC2LwCVhJXtl5lhtgmL/Hnfg8zRFxQ4uTMJ2BXMAPF m7fOZp7AyDcLSWoWktQCRqZVjJKpBcW56bnFhgWGeanlesWJucWleel6yfm5mxjBEaCluYNx +6oPeocYmTgYDzFKcDArifCy3TVKEOJNSaysSi3Kjy8qzUktPsQozcGiJM57oetkvJBAemJJ anZqakFqEUyWiYNTqoFJ/4L2uxA9UZNF78u4bRK2t578uKZdZk1gzLss8XUeMR/21LkatzKe ObT3pbBbP/vmuxon9++0dDyeOzHmF/eSqeX83wuVDHefPX1crzNz79nchwfqNzxWOcsmUKEf c+KTNF/Lwdz09vMm37cUT/5qtfek7KP9tdE575/cddaboitlED+dy+yn08sZ7x0uun6c4fyp YP7VMzLb/fZ8e6PwKWxe6VePLSuVmCdq5HbU/4zbl9c+X2SuntlSsZ+lUgW1/gl/GPw/n3OU idunze5dqvU++PS3zKCjaTPiOp4pl5SHHdkXHPjcRu7kx2X774t0KYjJZ/FVJlVImqh5ijQ1 Lz1V3L/CSKI/95i9p5sSS3FGoqEWc1FxIgA0qSED7wIAAA== X-CMS-MailID: 20210222081517epcas1p37fef998684dc9eae0bcd2764a3f82fb1 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20210222081517epcas1p37fef998684dc9eae0bcd2764a3f82fb1 References: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some of SD cards sets permanent write protection due to lifespan or internal problem. Host can find out it's protected permanantly during initialization. Once set read only during initialization, it could prevent unnecessary write operation in it. Signed-off-by: Seunghui Lee --- drivers/mmc/core/sd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 6fa51a6ed058..2c48d6504101 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -135,6 +135,9 @@ static int mmc_decode_csd(struct mmc_card *card) csd->erase_size = UNSTUFF_BITS(resp, 39, 7) + 1; csd->erase_size <<= csd->write_blkbits - 9; } + + if (UNSTUFF_BITS(resp, 13, 1)) + mmc_card_set_readonly(card); break; case 1: /* @@ -169,6 +172,9 @@ static int mmc_decode_csd(struct mmc_card *card) csd->write_blkbits = 9; csd->write_partial = 0; csd->erase_size = 1; + + if (UNSTUFF_BITS(resp, 13, 1)) + mmc_card_set_readonly(card); break; default: pr_err("%s: unrecognised CSD structure version %d\n", -- 2.29.0