From patchwork Thu Nov 23 17:43:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13466472 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F805C624B4 for ; Thu, 23 Nov 2023 17:44:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2711E6B067D; Thu, 23 Nov 2023 12:44:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 220B26B067E; Thu, 23 Nov 2023 12:44:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E8C96B067F; Thu, 23 Nov 2023 12:44:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0158A6B067D for ; Thu, 23 Nov 2023 12:44:10 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CADFFB6FEA for ; Thu, 23 Nov 2023 17:44:10 +0000 (UTC) X-FDA: 81489942660.06.918D2E6 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf29.hostedemail.com (Postfix) with ESMTP id 3E90F12001D for ; Thu, 23 Nov 2023 17:44:07 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf29.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700761449; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=76Vjr9A8OIcwKDK2GRWiqjut9jFAArBooGzrFSiDZFM=; b=qJqvCP26PeQNI2ILIRNKykOzheot4bSOO9v21ei3EiYJPBnVsnXn20UkKI7dXd1rkB5TuO REhSLbVyWYKsYJ7idYWJYOAhqsFQPBCYn8kD0BkRsOKjjmjTqkVu60jBCzygbFJCqD1Nqn PLdZVE59Ov08hH6bphKMKcVXFuUDjvs= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf29.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700761449; a=rsa-sha256; cv=none; b=x9pE7l9VtXslnWp3VycVHgnw7hNSVFeYFapgvWtnTshyu5pckYy4NNhRCgmZJmrceRkSli k0FQUaPUd1bIsjANwPNNmIVsHmyJMQ/lwsG5avVF9bcahKh9G7CghufrN3XLmX51pU/Xxk 2ZVMJO6QHJpooAJzaGjUkdqsIURJLfU= Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4SblnB2Vspz6K8sn; Fri, 24 Nov 2023 01:42:38 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 23 Nov 2023 17:44:03 +0000 From: To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 01/11] cxl/mbox: Add GET_SUPPORTED_FEATURES mailbox command Date: Fri, 24 Nov 2023 01:43:44 +0800 Message-ID: <20231123174355.1176-2-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20231123174355.1176-1-shiju.jose@huawei.com> References: <20231123174355.1176-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml100003.china.huawei.com (7.191.160.210) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Rspam-User: X-Stat-Signature: t8d54gkgqr8mmnjexuzdr7mikbxfiq6e X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3E90F12001D X-HE-Tag: 1700761447-852566 X-HE-Meta: U2FsdGVkX1/U44cPYKL3GlBi/Mkqn4/hwXuwqBz/v7Nmc1T93Vb7f6Ggd26JFv6LLbmoK/9nKNCma5/cPTWa4xF0CBB3YzdLRKS6oMlbouPeZjqTh/71gI6PFP4/KAQ5E3iOvGS9KChUYDwfbJhM6yA/U/7fITRdJBWbBP58ErqMM5UQJYj4ctqsEUqQ6J0j3QyKclGqqYl4kthW3TRkKY2s7JSha7r3dTZ3qXGUPRnA3HSdKTEl1ITmWDHfTLQIg3fbtIxj92MWIrwWygoWhxOIaL72BGfsfwbfZrPsiA5dqFhB8KKFC6g2wZTkZ9XZPE8zDrSD4D2PucymDznYuIyllfjvnyeoE7dFrusVl7dMf0/VX+puXQdnvLfnrHYstQVHFthEjBKm/5uyHLtpXYZ9RVkF2nTAWV3BCGBuP1w5ZHf6WpU66KAf+cgpwjBaWtLJRKXufXXndmAJKKACt7vTJOk/Z08CrJmqXpNT+zwvaSSLQ4vAfcPtf4nS8k2PusyXE2U3J+hsi7/+npuhmQSfx8iV7QMc77/Jwto4F45r3rDF22AgqwQbEy217yrKzRIRiia5K5htPenS9XEhoyKI4Rnk0xpk6kALVOem1BsNg8/0L/H/ukuGjfZDbyOoxOuYEPp4tVanv/wPuPjLadXkylcJUCGDwiC6kboMpbJ5+r8xxL9GCeCXJ8oVevhjmhgazidZe9Y1c5zx/+u4MFK11iLPLj1xXGd5lcN38NN7dI95DQj0EV3RmxoBnNt3lcbvWZR2ONIt+5iRygMeuIp6efq/vPmC+wyNv4+atKEuk5rpWVfnZoNADxTSBAly1JSbHrZGNW7j4zP/87VKwrb3nNnvvqO3TT4xRa6OmBE1tb4jWRIn/rv2Y+XQjf25vRLaSwjiwhRtND6+62mLxmtC1ZUvrsVSWu2m6VCljKn8nqAKMhKFlcaC2kZ3FbfGRxYpGcLi5eBK43W5nTp JnW2UIMf Kz87AT6lBpMl3UhLJXwozQ3yaZVIIjX+cQz5QgVrAZ/R64IDVzoXHN0mlhD7dok+kej4a4Q8NdfjOLnvjE+7LHR6Qk4LFTYeyLV9iaJGI42WSZUJ9Quslq2PXYu1Mph43M7efphRP+mKdNpaDsBIDygwEbhkjTw3q+J0vohiTUPVJwRdrGvvNT6gHyuG3GAv0CykJ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Shiju Jose Add support for GET_SUPPORTED_FEATURES mailbox command. CXL spec 3.0 section 8.2.9.6 describes optional device specific features. CXL devices supports features with changeable attributes. Get Supported Features retrieves the list of supported device specific features. The settings of a feature can be retrieved using Get Feature and optionally modified using Set Feature. Signed-off-by: Shiju Jose --- drivers/cxl/core/mbox.c | 23 ++++++++++++++++ drivers/cxl/cxlmem.h | 59 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index 36270dcfb42e..eb2741446b5f 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -1303,6 +1303,29 @@ int cxl_set_timestamp(struct cxl_memdev_state *mds) } EXPORT_SYMBOL_NS_GPL(cxl_set_timestamp, CXL); +int cxl_get_supported_features(struct cxl_memdev_state *mds, + struct cxl_mbox_get_supp_feats_in *pi, + void *feats_out) +{ + struct cxl_mbox_cmd mbox_cmd; + int rc; + + mbox_cmd = (struct cxl_mbox_cmd) { + .opcode = CXL_MBOX_OP_GET_SUPPORTED_FEATURES, + .size_in = sizeof(*pi), + .payload_in = pi, + .size_out = (size_t)pi->count, + .payload_out = feats_out, + .min_out = sizeof(struct cxl_mbox_get_supp_feats_out), + }; + rc = cxl_internal_send_cmd(mds, &mbox_cmd); + if (rc < 0) + return rc; + + return 0; +} +EXPORT_SYMBOL_NS_GPL(cxl_get_supported_features, CXL); + int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len, struct cxl_region *cxlr) { diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index a2fcbca253f3..d831dad748f5 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -506,6 +506,7 @@ enum cxl_opcode { CXL_MBOX_OP_SET_TIMESTAMP = 0x0301, CXL_MBOX_OP_GET_SUPPORTED_LOGS = 0x0400, CXL_MBOX_OP_GET_LOG = 0x0401, + CXL_MBOX_OP_GET_SUPPORTED_FEATURES = 0x0500, CXL_MBOX_OP_IDENTIFY = 0x4000, CXL_MBOX_OP_GET_PARTITION_INFO = 0x4100, CXL_MBOX_OP_SET_PARTITION_INFO = 0x4101, @@ -740,6 +741,61 @@ struct cxl_mbox_set_timestamp_in { } __packed; +/* Get Supported Features CXL 3.0 Spec 8.2.9.6.1 */ +/* + * Get Supported Features input payload + * CXL rev 3.0 section 8.2.9.6.1; Table 8-75 + */ +struct cxl_mbox_get_supp_feats_in { + __le32 count; + __le16 start_index; + u16 reserved; +} __packed; + +/* + * Get Supported Features Supported Feature Entry + * CXL rev 3.0 section 8.2.9.6.1; Table 8-77 + */ +/* Supported Feature Entry : Payload out attribute flags */ +#define CXL_FEAT_ENTRY_FLAG_CHANGABLE BIT(0) +#define CXL_FEAT_ENTRY_FLAG_DEEPEST_RESET_PERSISTENCE_MASK GENMASK(3, 1) + +enum cxl_feat_attrib_value_persistence { + CXL_FEAT_ATTRIB_VALUE_PERSISTENCE_NONE = 0x0, + CXL_FEAT_ATTRIB_VALUE_PERSISTENCE_CXL_RESET = 0x1, + CXL_FEAT_ATTRIB_VALUE_PERSISTENCE_HOT_RESET = 0x2, + CXL_FEAT_ATTRIB_VALUE_PERSISTENCE_WARM_RESET = 0x3, + CXL_FEAT_ATTRIB_VALUE_PERSISTENCE_COLD_RESET = 0x4, + CXL_FEAT_ATTRIB_VALUE_PERSISTENCE_MAX +}; + +#define CXL_FEAT_ENTRY_FLAG_PERSISTENCE_ACROSS_FW_UPDATE_MASK BIT(4) +#define CXL_FEAT_ENTRY_FLAG_PERSISTENCE_DEFAULT_SEL_SUPPORT_MASK BIT(5) +#define CXL_FEAT_ENTRY_FLAG_PERSISTENCE_SAVED_SEL_SUPPORT_MASK BIT(6) + +struct cxl_mbox_supp_feat_entry { + uuid_t uuid; + __le16 feat_index; + __le16 get_feat_size; + __le16 set_feat_size; + __le32 attrb_flags; + u8 get_feat_version; + u8 set_feat_version; + __le16 set_feat_effects; + u8 rsvd[18]; +} __packed; + +/* + * Get Supported Features output payload + * CXL rev 3.0 section 8.2.9.6.1; Table 8-76 + */ +struct cxl_mbox_get_supp_feats_out { + __le16 entries; + __le16 nsuppfeats_dev; + u32 reserved; + struct cxl_mbox_supp_feat_entry feat_entries[]; +} __packed; + /* Get Poison List CXL 3.0 Spec 8.2.9.8.4.1 */ struct cxl_mbox_poison_in { __le64 offset; @@ -867,6 +923,9 @@ void clear_exclusive_cxl_commands(struct cxl_memdev_state *mds, unsigned long *cmds); void cxl_mem_get_event_records(struct cxl_memdev_state *mds, u32 status); int cxl_set_timestamp(struct cxl_memdev_state *mds); +int cxl_get_supported_features(struct cxl_memdev_state *mds, + struct cxl_mbox_get_supp_feats_in *pi, + void *feats_out); int cxl_poison_state_init(struct cxl_memdev_state *mds); int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len, struct cxl_region *cxlr); From patchwork Thu Nov 23 17:43:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13466473 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B954EC636CB for ; Thu, 23 Nov 2023 17:44:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7046F6B067E; Thu, 23 Nov 2023 12:44:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B3A46B067F; Thu, 23 Nov 2023 12:44:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A41C6B0680; Thu, 23 Nov 2023 12:44:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4C1BC6B067E for ; Thu, 23 Nov 2023 12:44:11 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1C6CD161336 for ; Thu, 23 Nov 2023 17:44:11 +0000 (UTC) X-FDA: 81489942702.01.8316B04 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf14.hostedemail.com (Postfix) with ESMTP id 1898B10001D for ; Thu, 23 Nov 2023 17:44:08 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700761449; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9pRHHB9pzLsX42AwbC/oEQ0m1MV5cbTjMR1D0f0ENBg=; b=8gi2J19TBm09lFGCEB5s/AgQt1t9wR3/qpK1eh37WoLShrr7RjXUa1lAJlaC6H8u6DCpOP Jw2hS3hcgz8ptI0e2MC3Y6HrFx5fY4hW53d7VySqoQjwNgX4vvMVIta3P+qiH5E4047pi3 azU+wHduI1hyZHv/z7xhJbSD3omIdbo= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700761449; a=rsa-sha256; cv=none; b=mFGOZ+/Vwt1SlshjqYiEqDiGsK2P54tQKcr8q+jEebbgDRKkB/Mq5sK5sndGMfIXWvADYh VVFsGQHlCQcuid0uZ8LJfXaG9YrcPnbl5riFYnn4ZDz97lQnXrkVeJpAo0MdLMBd9PZs2L 6MGp8B5FAI0tj412CLzEgoMwGCKojuI= Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Sblpp0g6cz6J9yw; Fri, 24 Nov 2023 01:44:02 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 23 Nov 2023 17:44:04 +0000 From: To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 02/11] cxl/mbox: Add GET_FEATURE mailbox command Date: Fri, 24 Nov 2023 01:43:45 +0800 Message-ID: <20231123174355.1176-3-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20231123174355.1176-1-shiju.jose@huawei.com> References: <20231123174355.1176-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml100003.china.huawei.com (7.191.160.210) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 1898B10001D X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: fzm4gfoj7xnsciqm8wcjaiguur4m5cyu X-HE-Tag: 1700761448-236782 X-HE-Meta: U2FsdGVkX19ouC4StQIw6WU/Gf9zD6RZ3CQop8KqE9ZOcRXqIrNZOKpX8vaIB6CAhtWdk0kBrJeP22ym8PwVtHtG8z64lXzcvFccknqWuF4yUfJIL2QbCUN+3CJhmVUbEMibPUifsVnth/GUD3wQsZUzRFWTv7eHnWLzJsTTvzA/uw4dml9rTHwXgpyf87nk/RkLxmCZ1VB1VSOpRxcyfWKGblGIlKlBvFTt3g4YGHkZI7iYpfEC5WtiCoRqvChjDk9f0lxYJ+2hiu2ik/SWN0evSnDolwdbqQ1SatB7TgFauopPdeJCyDF36bms7MoWG4e8X/M/8PmBwj/cczPo3mQF3SxQcNbgipM7uPwpJqTgLtYnOHfxIZwf6DKRbVMJ5pg0v/bE+71kJbDks6NjoJ3taQjH5t0Mpz8SEQiJLFWCKpZ4Iv3wPBDEiNFbFcDgrVMI7K5BhWsa7FK6OYAXnyaVDak481cgYbWCqYzWS4+ntaNma3ElKMDxzMZ6uEQu5pcbG2TC6e76QrFiKkzvIP4uQ07Fcuz8HMfB65sptwqD0cobOTvr3O2yp9IB1QSR779C6ZRHVoB8zFNECY0bjjuKBTEKQKlJbVHRVGBj2EuSdpMQf28TTEPlkg03cSDH4c0B1SJbayK6WDy4MzTHgwz7Yi+HbrSMOkQAJfYJnAU1D6htNVWgRNGG5gVQgFJuiPrJCgbNMdm54LHJwAzuJLplwugRpNwCaBZcwrKPyEHd7wOkyuzgRzp9rQvrVQH/qTOQW90lcjwoP+zM1msQ2sv9rjKhzTaL4T8Urw+8kgI5Y7eSAfMnJnigI+Ge0XTy1uSFxp4CFUjBQTPvwWF+HHQSTeRDwT9jKsBvGCOs8rIDQl48p1HSDRc3oCn2jozdBtFQTSXFg8PqDhDMfOSk6qiTjBpppUp0FvWhXHHf2EpzYf18NX3y5geqAIAFikS3oUh5orAGl+7DBgVgdwX 0OZjgTOA aRSV6QJID0z0/IdF9YO+Hdtc4almUQRQS2TbWV9eaXmkhH69QLJArK/7kluf71/at0CCDUJ26RZwRRxsSqjFirC441sXyMiCxZ6kxYdMETwy/vjq4mjVHV9DJAlK6a6aC/q0JbKAKUPc6FgA49UrJ4+b7u+9Ga3uHFzbd8Fu193xfC0WtzVOIr/0R4lBMHxkqUBpJHt4G9jPy0AKzsAtRCxAXV2fExMHQGJkpW9TBEDKD2yc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Shiju Jose Add support for GET_FEATURE mailbox command. CXL spec 3.0 section 8.2.9.6 describes optional device specific features. The settings of a feature can be retrieved using Get Feature command. Signed-off-by: Shiju Jose --- drivers/cxl/core/mbox.c | 22 ++++++++++++++++++++++ drivers/cxl/cxlmem.h | 23 +++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index eb2741446b5f..759b7e7e6a09 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -1326,6 +1326,28 @@ int cxl_get_supported_features(struct cxl_memdev_state *mds, } EXPORT_SYMBOL_NS_GPL(cxl_get_supported_features, CXL); +int cxl_get_feature(struct cxl_memdev_state *mds, + struct cxl_mbox_get_feat_in *pi, void *feat_out) +{ + struct cxl_mbox_cmd mbox_cmd; + int rc; + + mbox_cmd = (struct cxl_mbox_cmd) { + .opcode = CXL_MBOX_OP_GET_FEATURE, + .size_in = sizeof(*pi), + .payload_in = pi, + .size_out = (size_t)pi->count, + .payload_out = feat_out, + .min_out = (size_t)pi->count, + }; + rc = cxl_internal_send_cmd(mds, &mbox_cmd); + if (rc < 0) + return rc; + + return 0; +} +EXPORT_SYMBOL_NS_GPL(cxl_get_feature, CXL); + int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len, struct cxl_region *cxlr) { diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index d831dad748f5..92c1f2a44713 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -507,6 +507,7 @@ enum cxl_opcode { CXL_MBOX_OP_GET_SUPPORTED_LOGS = 0x0400, CXL_MBOX_OP_GET_LOG = 0x0401, CXL_MBOX_OP_GET_SUPPORTED_FEATURES = 0x0500, + CXL_MBOX_OP_GET_FEATURE = 0x0501, CXL_MBOX_OP_IDENTIFY = 0x4000, CXL_MBOX_OP_GET_PARTITION_INFO = 0x4100, CXL_MBOX_OP_SET_PARTITION_INFO = 0x4101, @@ -796,6 +797,26 @@ struct cxl_mbox_get_supp_feats_out { struct cxl_mbox_supp_feat_entry feat_entries[]; } __packed; +/* Get Feature CXL 3.0 Spec 8.2.9.6.2 */ +/* + * Get Feature input payload + * CXL rev 3.0 section 8.2.9.6.2; Table 8-79 + */ +/* Get Feature : Payload in selection */ +enum cxl_get_feat_selection { + CXL_GET_FEAT_SEL_CURRENT_VALUE = 0x0, + CXL_GET_FEAT_SEL_DEFAULT_VALUE = 0x1, + CXL_GET_FEAT_SEL_SAVED_VALUE = 0x2, + CXL_GET_FEAT_SEL_MAX +}; + +struct cxl_mbox_get_feat_in { + uuid_t uuid; + __le16 offset; + __le16 count; + u8 selection; +} __packed; + /* Get Poison List CXL 3.0 Spec 8.2.9.8.4.1 */ struct cxl_mbox_poison_in { __le64 offset; @@ -926,6 +947,8 @@ int cxl_set_timestamp(struct cxl_memdev_state *mds); int cxl_get_supported_features(struct cxl_memdev_state *mds, struct cxl_mbox_get_supp_feats_in *pi, void *feats_out); +int cxl_get_feature(struct cxl_memdev_state *mds, + struct cxl_mbox_get_feat_in *pi, void *feat_out); int cxl_poison_state_init(struct cxl_memdev_state *mds); int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len, struct cxl_region *cxlr); From patchwork Thu Nov 23 17:43:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13466474 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A59F4C61D97 for ; Thu, 23 Nov 2023 17:44:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68F1A6B067F; Thu, 23 Nov 2023 12:44:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 618786B0681; Thu, 23 Nov 2023 12:44:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 46A9E6B0682; Thu, 23 Nov 2023 12:44:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 349A36B067F for ; Thu, 23 Nov 2023 12:44:12 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id F2B5F12020E for ; Thu, 23 Nov 2023 17:44:11 +0000 (UTC) X-FDA: 81489942702.22.D4656D2 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf12.hostedemail.com (Postfix) with ESMTP id E9A5D40009 for ; Thu, 23 Nov 2023 17:44:09 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf12.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700761450; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=592l1kS3R4jev5cRSwIwE8LySJya3R/tD+q2DViGQYY=; b=57kKsSDPjv0+OFqmMWIg6FiM9Uozexhp3G5HyMkEx1wJVRIPV6bGzmezXmIjU9S3gMkJGg EzUt+OItLLYr6/f/LI97zgAPQqz5BZd6qQ67+WqS4/B1L4OiT/bTNfd0pHjZR2djbp2ZUe F9FTFe20AK7SFCmt6fypP3O3OKuPNyY= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf12.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700761450; a=rsa-sha256; cv=none; b=3MaEYK8ak0P1G2NTRqUHxKgexG0FD+DhYCjgg1cAi4ZvFRfY+Y+F8AfQya9spD2Z9CMcCV UUaza4vkxsLP5gIZEr4NRidQEoAIwS6kRd8Rdk3PKT36Ors5CxjcIH4y6Br7Vsgi/g7FgC q9dQl0v6Qc7RINldBarz7q5HFLePFh0= Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Sblpp5BsQz6JB09; Fri, 24 Nov 2023 01:44:02 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 23 Nov 2023 17:44:05 +0000 From: To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 03/11] cxl/mbox: Add SET_FEATURE mailbox command Date: Fri, 24 Nov 2023 01:43:46 +0800 Message-ID: <20231123174355.1176-4-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20231123174355.1176-1-shiju.jose@huawei.com> References: <20231123174355.1176-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml100003.china.huawei.com (7.191.160.210) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Rspam-User: X-Stat-Signature: uwety91gfbx6hoy5uddp6jc75t8wnd33 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: E9A5D40009 X-HE-Tag: 1700761449-651207 X-HE-Meta: U2FsdGVkX1/TLsltBdVYCjomAottdZcRFc55szkX6sdzTUQWFZ9/1HR2oZm0Cd9dOdSfDk57oNlPDqUCssha/7V3bGbQR6zrD2OcB0ODHK5uKK1FP1s/iYnv2hpFr9q+ql3nErtt/wT5QTvyQWd202GwilrBYIPM+/a12cOe+/jtCInbX/rSu6iZJnoBoOAS9gLojDBAgqb6/cLE6DtNp6bbxIKGQmiAtGd654LcIo6QROi2FJO+BIQN06Gc1yc1caWLZkernCKE03ZB/YsWGUuO6UjcUE9ME+UZDWk2dYfAcW+19+ngAuWG5KX+0e8x2o2TH+odZD6wKzCRP2/QZlg4inp4CRI+Hrf05yPOjR2UlPktP1PZpkKsEadbWGNNtguOkGmLQsWRWSz/FFjde0wXTdNmKv8HnNJqNMKlxbftsUUazjzgMle6xKymbN2Ca3tDiE6bYOwGh1QlQ4kW/25rRfbG0547ZgO49rEnuPzTqEQqQAgqsiejDhRA0Mhynvps8G6+JG569rIDjK4cKGWD53ZGHM2L9ha2DhEu/E5+pzRvkcFMwDf8UmTWQRAztiFZ1TiD0AW/pOpRwgeHZq/uqrPqViyGuhkTl5cuWhpG7CYr0yQejdSU4dXT8iJyILamD6SIjogu/gr/Q2CvYPw3pBL0NQBWyvZrESSrJN2j5WWVX0dTQm+dvXB61pRIBrzLl1cnhheAoprGK4Qhx825g3kbid7Ggi9cIPK7rPeiyVdHOAdcQ0winm3GoyNjVd8fgbXEgz866wIswPPE9Q2OOJt97XwKWU9cpJ0btRQCauvjxPqyQxkuWf5rgkwaZd3GdsCUAsq8ddJmqO6oCrSh3yFYpujAoBhDBHtk4cazIrLQGEs5pSRVT/9SCC9Eq9kv9K/Wa9nBdd7TEROrEBnW/kxMSP9C3zyuFUI0bTBTB9Z9A/cyl8ViOnDglCA5NV8E8M7c/kFPtBQIEOr Ieikhqh4 7rM1Q3TEjeLY8hyXxi+xIAstv8f4F1wr6mRnW10mg41o7ZQuiUggvzH/JzXt0ryTJaCTu4B/09kb/UiDjDGwnhXGoPsSrfT3k1Y/4T+77YbYfcSkqHmbjSliafFKOUfBPaZQL/Ju+eyjNoLdPmA77EnuFNdw4TQeM8mISxREV4BFOcj7m84rhsrQsGZN6nphrJN1pQaW8UIv1IViK5SwS9X4dUb1vFvkNI/VDmisCKArY7to= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Shiju Jose Add support for SET_FEATURE mailbox command. CXL spec 3.0 section 8.2.9.6 describes optional device specific features. CXL devices supports features with changeable attributes. The settings of a feature can be optionally modified using Set Feature command. Signed-off-by: Shiju Jose --- drivers/cxl/core/mbox.c | 14 ++++++++++++++ drivers/cxl/cxlmem.h | 27 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index 759b7e7e6a09..e8aecf038a6d 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -1348,6 +1348,20 @@ int cxl_get_feature(struct cxl_memdev_state *mds, } EXPORT_SYMBOL_NS_GPL(cxl_get_feature, CXL); +int cxl_set_feature(struct cxl_memdev_state *mds, void *feat_in, size_t size) +{ + struct cxl_mbox_cmd mbox_cmd; + + mbox_cmd = (struct cxl_mbox_cmd) { + .opcode = CXL_MBOX_OP_SET_FEATURE, + .size_in = size, + .payload_in = feat_in, + }; + + return cxl_internal_send_cmd(mds, &mbox_cmd); +} +EXPORT_SYMBOL_NS_GPL(cxl_set_feature, CXL); + int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len, struct cxl_region *cxlr) { diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 92c1f2a44713..46131dcd0900 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -508,6 +508,7 @@ enum cxl_opcode { CXL_MBOX_OP_GET_LOG = 0x0401, CXL_MBOX_OP_GET_SUPPORTED_FEATURES = 0x0500, CXL_MBOX_OP_GET_FEATURE = 0x0501, + CXL_MBOX_OP_SET_FEATURE = 0x0502, CXL_MBOX_OP_IDENTIFY = 0x4000, CXL_MBOX_OP_GET_PARTITION_INFO = 0x4100, CXL_MBOX_OP_SET_PARTITION_INFO = 0x4101, @@ -817,6 +818,31 @@ struct cxl_mbox_get_feat_in { u8 selection; } __packed; +/* Set Feature CXL 3.0 Spec 8.2.9.6.3 */ +/* + * Set Feature input payload + * CXL rev 3.0 section 8.2.9.6.3; Table 8-81 + */ +/* Set Feature : Payload in flags */ +#define CXL_SET_FEAT_FLAG_DATA_TRANSFER_MASK GENMASK(2, 0) +enum cxl_set_feat_flag_data_transfer { + CXL_SET_FEAT_FLAG_FULL_DATA_TRANSFER = 0x0, + CXL_SET_FEAT_FLAG_INITIATE_DATA_TRANSFER = 0x1, + CXL_SET_FEAT_FLAG_CONTINUE_DATA_TRANSFER = 0x2, + CXL_SET_FEAT_FLAG_FINISH_DATA_TRANSFER = 0x3, + CXL_SET_FEAT_FLAG_ABORT_DATA_TRANSFER = 0x4, + CXL_SET_FEAT_FLAG_DATA_TRANSFER_MAX +}; +#define CXL_SET_FEAT_FLAG_MOD_VALUE_SAVED_ACROSS_RESET BIT(3) + +struct cxl_mbox_set_feat_in { + uuid_t uuid; + __le32 flags; + __le16 offset; + u8 version; + u8 rsvd[9]; +} __packed; + /* Get Poison List CXL 3.0 Spec 8.2.9.8.4.1 */ struct cxl_mbox_poison_in { __le64 offset; @@ -949,6 +975,7 @@ int cxl_get_supported_features(struct cxl_memdev_state *mds, void *feats_out); int cxl_get_feature(struct cxl_memdev_state *mds, struct cxl_mbox_get_feat_in *pi, void *feat_out); +int cxl_set_feature(struct cxl_memdev_state *mds, void *feat_in, size_t size); int cxl_poison_state_init(struct cxl_memdev_state *mds); int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len, struct cxl_region *cxlr); From patchwork Thu Nov 23 17:43:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13466476 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63DFCC5AD4C for ; Thu, 23 Nov 2023 17:44:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E34446B0682; Thu, 23 Nov 2023 12:44:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E07FB6B0685; Thu, 23 Nov 2023 12:44:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AFF406B0682; Thu, 23 Nov 2023 12:44:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 81FFA6B0683 for ; Thu, 23 Nov 2023 12:44:12 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A5837A1843 for ; Thu, 23 Nov 2023 17:44:11 +0000 (UTC) X-FDA: 81489942702.24.A4FA8DC Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf19.hostedemail.com (Postfix) with ESMTP id 9E8491A001D for ; Thu, 23 Nov 2023 17:44:09 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700761449; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6v2zhrb9Rep/rM5TqMOHsmtTSY20ax2RguWtt5jCYdc=; b=MdkmAc1QvSKMi4L717XUB81vjXi0xUSh/8Nv2PlNW4io4Mt4yhRW8KVcp/Dp9zRwviGSkq pSXT3m+3xhksfQgfY03ZNVovJD9T5nBzu8N2G6qER0fiZ+jV/hMv7sbWjtuUCSpRShC+k/ WjS7/nXFLiXYDvDNhj/gSnMK9lxoHyQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700761449; a=rsa-sha256; cv=none; b=u1dY60au+m91DDhxs1Xfo65OVPHwKZGSkXGwkeWc9C/2tJP4LxBkgPdTegTksvmxEs05rO Rvph4jVz4S9bWFQ01hS+bOX2vOQpxtRq99YdVTeOZ1tZnjJDz4mhyxe01iI2pZJycrjHrQ 0Xm5Jry9bxHQevbJDQ2gRYtZDEKGu6w= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Sbljy1y30z6K5qC; Fri, 24 Nov 2023 01:39:50 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 23 Nov 2023 17:44:06 +0000 From: To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 04/11] cxl/memscrub: Add CXL device patrol scrub control feature Date: Fri, 24 Nov 2023 01:43:47 +0800 Message-ID: <20231123174355.1176-5-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20231123174355.1176-1-shiju.jose@huawei.com> References: <20231123174355.1176-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml100003.china.huawei.com (7.191.160.210) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Stat-Signature: 8onb7um4r14ey5ikopm5yy4m1asow1qn X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 9E8491A001D X-Rspam-User: X-HE-Tag: 1700761449-168920 X-HE-Meta: U2FsdGVkX19dwnrE50o5UPPnxZPqxilm+AylfvzK2RjF4vQkFJJL/d7cMStpkdfDh27eSVCI2bW9pNeJbjSIZooQWZ7KwKN6d5ZDl2tzO3Cm8xKSXsAabenjgh85KNSEH8QZuTYZvL51VwR8XOZsElt5Rmli8B+aHCc9kJdwDbqAE8hCVFdqCQoxFnRd4Qg9g7VKRtXvB76VvRL1RFlVo4EI3KJyBOYw3by0kP1hdp6Hpci4BafA56YwGGq43zDYwxboZehdr3771GW76jOIT1ptfYmDYKJsk9BTe8F6QbDea+DcIYRuM34hcltTs+XKrtXw1qQuIBjpLMHjNDyh8QoV1ttYivl1CHf6+kGPJQVcyxSSwfFhx9oHTY2aADhXx4NqMbb1Rsy9b1hF2p9UvKxiVlcRzdZe9TFCR61BOT9+bK4WJaSkHpBOuZdkZgVVwCdh4YqI+LydR9bdle+qsSCVKeUOMYyZ2cmbekyU9L8PfCDa7uOK4LncqWo73O7qLT14x3QBZfV2B4ruJeM0OKQ3IqXhbyVnwTqNt2AsK31i+DuJun3dDIrkOSCoSm8kDYpjKokwCpphLpoQs6hzliX0pnosyrA0Ul22dT3RwNTYg6hopect/oj+o6RcwSPor6PHp0uMpBwUpTOsWalJMhQMe8NYZNUXHwpBB3Fun5xde6yXJwQbZTWg7+FTRjOUjew4Yqyqkx/a97k++sYerS8HQhZ3JxtHfBtiyy6xkGKknMH/8qfY9i8UYrpD2UNtUe+j6OKxeywqkciId1LLF2OEvW6ndwpAMHByIhyWOX7cfDHrWGzfu0KcQgHeyiJ+g1wp0/MY91cFXRz6PGg7USH8W4gD2rDNaWm5aljRLBsF1exkwSK8+9RGuScl5Z1b5dBoBQvj/nFo2332vdipDgp9KWVns2ayHatwoZe2M69izuT0aTQvpq/exhj+W4ph4Lr4QBQM3NKYULhGmi6 tnQQt2Wx jCU3iXqCk+sU+Ha/gR9anbCFInOyK9B6pUGMVUhZ3soOVkOmycobdF4pgqctzP4ng7+R/O1GUiltfOfMBnwF9yO0ZVmZuGuN4++zZfzUMV3tSF0hwmOj6XwkkmkgYIlhcJ+PFuYirKLwSwlCfkM6o7NWjvZQBv03OJvWsLz67aB0FrM4qz7n3sa0izG+X3vE5FGmY X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Shiju Jose CXL spec 3.1 section 8.2.9.9.11.1 describes the device patrol scrub control feature. The device patrol scrub proactively locates and makes corrections to errors in regular cycle. The patrol scrub control allows the request to configure patrol scrub input configurations. The patrol scrub control allows the requester to specify the number of hours for which the patrol scrub cycles must be completed, provided that the requested number is not less than the minimum number of hours for the patrol scrub cycle that the device is capable of. In addition, the patrol scrub controls allow the host to disable and enable the feature in case disabling of the feature is needed for other purposes such as performance-aware operations which require the background operations to be turned off. Signed-off-by: Shiju Jose --- drivers/cxl/Kconfig | 17 +++ drivers/cxl/core/Makefile | 1 + drivers/cxl/core/memscrub.c | 266 ++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 8 ++ drivers/cxl/pci.c | 5 + 5 files changed, 297 insertions(+) create mode 100644 drivers/cxl/core/memscrub.c diff --git a/drivers/cxl/Kconfig b/drivers/cxl/Kconfig index 8ea1d340e438..67d88f9bf52b 100644 --- a/drivers/cxl/Kconfig +++ b/drivers/cxl/Kconfig @@ -154,4 +154,21 @@ config CXL_PMU monitoring units and provide standard perf based interfaces. If unsure say 'm'. + +config CXL_SCRUB + bool "CXL: Memory scrub feature" + depends on CXL_PCI + depends on CXL_MEM + help + The CXL memory scrub control is an optional feature allows host to + control the scrub configurations of CXL Type 3 devices, which + support patrol scrub and/or DDR5 ECS(Error Check Scrub). + + Say 'y/n' to enable/disable the CXL memory scrub driver that will + attach to CXL.mem devices for memory scrub control feature. See + sections 8.2.9.9.11.1 and 8.2.9.9.11.2 in the CXL 3.1 specification + for a detailed description of CXL memory scrub control features. + + If unsure say 'n'. + endif diff --git a/drivers/cxl/core/Makefile b/drivers/cxl/core/Makefile index 1f66b5d4d935..99e3202f868f 100644 --- a/drivers/cxl/core/Makefile +++ b/drivers/cxl/core/Makefile @@ -15,3 +15,4 @@ cxl_core-y += hdm.o cxl_core-y += pmu.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o +cxl_core-$(CONFIG_CXL_SCRUB) += memscrub.o diff --git a/drivers/cxl/core/memscrub.c b/drivers/cxl/core/memscrub.c new file mode 100644 index 000000000000..a74f4efa207e --- /dev/null +++ b/drivers/cxl/core/memscrub.c @@ -0,0 +1,266 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * cxl_memscrub.c - CXL memory scrub driver + * + * Copyright (c) 2023 HiSilicon Limited. + * + * - Provides functions to configure patrol scrub + * feature of the CXL memory devices. + */ + +#define pr_fmt(fmt) "CXL_MEM_SCRUB: " fmt + +#include + +/* CXL memory scrub feature common definitions */ +#define CXL_SCRUB_MAX_ATTRB_RANGE_LENGTH 128 + +static int cxl_mem_get_supported_feature_entry(struct cxl_memdev *cxlmd, const uuid_t *feat_uuid, + struct cxl_mbox_supp_feat_entry *feat_entry_out) +{ + struct cxl_mbox_get_supp_feats_out *feats_out __free(kvfree) = NULL; + struct cxl_mbox_supp_feat_entry *feat_entry; + struct cxl_dev_state *cxlds = cxlmd->cxlds; + struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds); + struct cxl_mbox_get_supp_feats_in pi; + int feat_index, count; + int nentries; + int ret; + + feat_index = 0; + pi.count = sizeof(struct cxl_mbox_get_supp_feats_out) + + sizeof(struct cxl_mbox_supp_feat_entry); + feats_out = kvmalloc(pi.count, GFP_KERNEL); + if (!feats_out) + return -ENOMEM; + + do { + pi.start_index = feat_index; + memset(feats_out, 0, pi.count); + ret = cxl_get_supported_features(mds, &pi, feats_out); + if (ret) + return ret; + + nentries = feats_out->entries; + if (!nentries) + break; + + /* Check CXL memdev supports the feature */ + feat_entry = (void *)feats_out->feat_entries; + for (count = 0; count < nentries; count++, feat_entry++) { + if (uuid_equal(&feat_entry->uuid, feat_uuid)) { + memcpy(feat_entry_out, feat_entry, sizeof(*feat_entry_out)); + return 0; + } + } + feat_index += nentries; + } while (nentries); + + return -ENOTSUPP; +} + +/* CXL memory patrol scrub control definitions */ +#define CXL_MEMDEV_PS_GET_FEAT_VERSION 0x01 +#define CXL_MEMDEV_PS_SET_FEAT_VERSION 0x01 + +static const uuid_t cxl_patrol_scrub_uuid = + UUID_INIT(0x96dad7d6, 0xfde8, 0x482b, 0xa7, 0x33, 0x75, 0x77, 0x4e, \ + 0x06, 0xdb, 0x8a); + +/* CXL memory patrol scrub control functions */ +struct cxl_patrol_scrub_context { + struct device *dev; + u16 get_feat_size; + u16 set_feat_size; + bool scrub_cycle_changeable; +}; + +/** + * struct cxl_memdev_ps_params - CXL memory patrol scrub parameter data structure. + * @enable: [IN] enable(1)/disable(0) patrol scrub. + * @scrub_cycle_changeable: [OUT] scrub cycle attribute of patrol scrub is changeable. + * @speed: [IN] Requested patrol scrub cycle in hours. + * [OUT] Current patrol scrub cycle in hours. + * @min_speed:[OUT] minimum patrol scrub cycle, in hours, supported. + * @speed_avail:[OUT] Supported patrol scrub cycle in hours. + */ +struct cxl_memdev_ps_params { + bool enable; + bool scrub_cycle_changeable; + u16 speed; + u16 min_speed; + char speed_avail[CXL_SCRUB_MAX_ATTRB_RANGE_LENGTH]; +}; + +enum { + CXL_MEMDEV_PS_PARAM_ENABLE = 0, + CXL_MEMDEV_PS_PARAM_SPEED, +}; + +#define CXL_MEMDEV_PS_SCRUB_CYCLE_CHANGE_CAP_MASK BIT(0) +#define CXL_MEMDEV_PS_SCRUB_CYCLE_REALTIME_REPORT_CAP_MASK BIT(1) +#define CXL_MEMDEV_PS_CUR_SCRUB_CYCLE_MASK GENMASK(7, 0) +#define CXL_MEMDEV_PS_MIN_SCRUB_CYCLE_MASK GENMASK(15, 8) +#define CXL_MEMDEV_PS_FLAG_ENABLED_MASK BIT(0) + +struct cxl_memdev_ps_feat_read_attrbs { + u8 scrub_cycle_cap; + __le16 scrub_cycle; + u8 scrub_flags; +} __packed; + +struct cxl_memdev_ps_set_feat_pi { + struct cxl_mbox_set_feat_in pi; + u8 scrub_cycle_hr; + u8 scrub_flags; +} __packed; + +static int cxl_mem_ps_get_attrbs(struct device *dev, + struct cxl_memdev_ps_params *params) +{ + struct cxl_memdev_ps_feat_read_attrbs *rd_attrbs __free(kvfree) = NULL; + struct cxl_mbox_get_feat_in pi = { + .uuid = cxl_patrol_scrub_uuid, + .offset = 0, + .count = sizeof(struct cxl_memdev_ps_feat_read_attrbs), + .selection = CXL_GET_FEAT_SEL_CURRENT_VALUE, + }; + struct cxl_memdev *cxlmd = to_cxl_memdev(dev); + struct cxl_dev_state *cxlds = cxlmd->cxlds; + struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds); + int ret; + + if (!mds) + return -EFAULT; + + rd_attrbs = kvmalloc(pi.count, GFP_KERNEL); + if (!rd_attrbs) + return -ENOMEM; + + ret = cxl_get_feature(mds, &pi, rd_attrbs); + if (ret) { + params->enable = 0; + params->speed = 0; + snprintf(params->speed_avail, CXL_SCRUB_MAX_ATTRB_RANGE_LENGTH, + "Unavailable"); + return ret; + } + params->scrub_cycle_changeable = FIELD_GET(CXL_MEMDEV_PS_SCRUB_CYCLE_CHANGE_CAP_MASK, + rd_attrbs->scrub_cycle_cap); + params->enable = FIELD_GET(CXL_MEMDEV_PS_FLAG_ENABLED_MASK, + rd_attrbs->scrub_flags); + params->speed = FIELD_GET(CXL_MEMDEV_PS_CUR_SCRUB_CYCLE_MASK, + rd_attrbs->scrub_cycle); + params->min_speed = FIELD_GET(CXL_MEMDEV_PS_MIN_SCRUB_CYCLE_MASK, + rd_attrbs->scrub_cycle); + snprintf(params->speed_avail, CXL_SCRUB_MAX_ATTRB_RANGE_LENGTH, + "Minimum scrub cycle = %d hour", params->min_speed); + + return 0; +} + +static int __maybe_unused +cxl_mem_ps_set_attrbs(struct device *dev, struct cxl_memdev_ps_params *params, + u8 param_type) +{ + struct cxl_memdev_ps_set_feat_pi set_pi = { + .pi.uuid = cxl_patrol_scrub_uuid, + .pi.flags = CXL_SET_FEAT_FLAG_MOD_VALUE_SAVED_ACROSS_RESET | + CXL_SET_FEAT_FLAG_FULL_DATA_TRANSFER, + .pi.offset = 0, + .pi.version = CXL_MEMDEV_PS_SET_FEAT_VERSION, + }; + struct cxl_memdev *cxlmd = to_cxl_memdev(dev); + struct cxl_dev_state *cxlds = cxlmd->cxlds; + struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds); + struct cxl_memdev_ps_params rd_params; + int ret; + + if (!mds) + return -EFAULT; + + ret = cxl_mem_ps_get_attrbs(dev, &rd_params); + if (ret) { + dev_err(dev, "Get cxlmemdev patrol scrub params fail ret=%d\n", + ret); + return ret; + } + + switch (param_type) { + case CXL_MEMDEV_PS_PARAM_ENABLE: + set_pi.scrub_flags = FIELD_PREP(CXL_MEMDEV_PS_FLAG_ENABLED_MASK, + params->enable); + set_pi.scrub_cycle_hr = FIELD_PREP(CXL_MEMDEV_PS_CUR_SCRUB_CYCLE_MASK, + rd_params.speed); + break; + case CXL_MEMDEV_PS_PARAM_SPEED: + if (params->speed < rd_params.min_speed) { + dev_err(dev, "Invalid CXL patrol scrub cycle(%d) to set\n", + params->speed); + dev_err(dev, "Minimum supported CXL patrol scrub cycle in hour %d\n", + params->min_speed); + return -EINVAL; + } + set_pi.scrub_cycle_hr = FIELD_PREP(CXL_MEMDEV_PS_CUR_SCRUB_CYCLE_MASK, + params->speed); + set_pi.scrub_flags = FIELD_PREP(CXL_MEMDEV_PS_FLAG_ENABLED_MASK, + rd_params.enable); + break; + default: + dev_err(dev, "Invalid CXL patrol scrub parameter to set\n"); + return -EINVAL; + } + + ret = cxl_set_feature(mds, &set_pi, sizeof(set_pi)); + if (ret) { + dev_err(dev, "CXL patrol scrub set feature fail ret=%d\n", + ret); + return ret; + } + + /* Verify attribute set successfully */ + if (param_type == CXL_MEMDEV_PS_PARAM_SPEED) { + ret = cxl_mem_ps_get_attrbs(dev, &rd_params); + if (ret) { + dev_err(dev, "Get cxlmemdev patrol scrub params fail ret=%d\n", ret); + return ret; + } + if (rd_params.speed != params->speed) + return -EFAULT; + } + + return 0; +} + +int cxl_mem_patrol_scrub_init(struct cxl_memdev *cxlmd) +{ + struct cxl_patrol_scrub_context *cxl_ps_ctx; + struct cxl_mbox_supp_feat_entry feat_entry; + struct cxl_memdev_ps_params params; + int ret; + + ret = cxl_mem_get_supported_feature_entry(cxlmd, &cxl_patrol_scrub_uuid, + &feat_entry); + if (ret < 0) + return ret; + + if (!(feat_entry.attrb_flags & CXL_FEAT_ENTRY_FLAG_CHANGABLE)) + return -ENOTSUPP; + + cxl_ps_ctx = devm_kzalloc(&cxlmd->dev, sizeof(*cxl_ps_ctx), GFP_KERNEL); + if (!cxl_ps_ctx) + return -ENOMEM; + + cxl_ps_ctx->get_feat_size = feat_entry.get_feat_size; + cxl_ps_ctx->set_feat_size = feat_entry.set_feat_size; + ret = cxl_mem_ps_get_attrbs(&cxlmd->dev, ¶ms); + if (ret) { + dev_err(&cxlmd->dev, "Get CXL patrol scrub params fail ret=%d\n", + ret); + return ret; + } + cxl_ps_ctx->scrub_cycle_changeable = params.scrub_cycle_changeable; + + return 0; +} +EXPORT_SYMBOL_NS_GPL(cxl_mem_patrol_scrub_init, CXL); diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 46131dcd0900..25c46e72af16 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -983,6 +983,14 @@ int cxl_trigger_poison_list(struct cxl_memdev *cxlmd); int cxl_inject_poison(struct cxl_memdev *cxlmd, u64 dpa); int cxl_clear_poison(struct cxl_memdev *cxlmd, u64 dpa); +/* cxl memory scrub functions */ +#ifdef CONFIG_CXL_SCRUB +int cxl_mem_patrol_scrub_init(struct cxl_memdev *cxlmd); +#else +static inline int cxl_mem_patrol_scrub_init(struct cxl_memdev *cxlmd) +{ return -ENOTSUPP; } +#endif + #ifdef CONFIG_CXL_SUSPEND void cxl_mem_active_inc(void); void cxl_mem_active_dec(void); diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index 0155fb66b580..acc337b8c365 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -881,6 +881,11 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (rc) return rc; + /* + * Initialize optional CXL scrub features + */ + cxl_mem_patrol_scrub_init(cxlmd); + rc = devm_cxl_sanitize_setup_notifier(&pdev->dev, cxlmd); if (rc) return rc; From patchwork Thu Nov 23 17:43:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13466477 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80408C61D97 for ; Thu, 23 Nov 2023 17:44:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D3C66B0683; Thu, 23 Nov 2023 12:44:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 359256B0684; Thu, 23 Nov 2023 12:44:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 117436B0686; Thu, 23 Nov 2023 12:44:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E96A36B0683 for ; Thu, 23 Nov 2023 12:44:12 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C675316146F for ; Thu, 23 Nov 2023 17:44:12 +0000 (UTC) X-FDA: 81489942744.10.2C00C4C Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf23.hostedemail.com (Postfix) with ESMTP id B2EA314001D for ; Thu, 23 Nov 2023 17:44:10 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf23.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700761451; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5ghYT3Iglz32dt2xFr79OfFN5+CTXbu64JWBuQTl0Gw=; b=iz3xyQaUOVoLVShnPeFNF0cVHdIp9vM9iXhwKiP6RnMH1r+8lCsMMsdf8d6OoMLhRV0dtU 4D7l7fcsmN2AHErdq+CYex8KukQQOUljoLruafn6hnlbcvQk8hDZ2N1tLVY0Mpp9V7xYyT Ic1RhFkStzPY8XmDpRswSWHxEqLtGKU= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf23.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700761451; a=rsa-sha256; cv=none; b=S07AbJ2BnTUQ8LGK57LUdrgpsag8/ZIPsztQwUKPKI734/e48rZ/nDJyMA67r6HC5umWw9 ugek4SA4SLr/umEHt2iyF5wit+i3kgCzG+ENuegPs3net31fu6o5FfpITcpxDz8cC1VqHL CbrpownrbZ4Iu6jYsOAAhhiRJ/+gs6E= Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Sblpr6qCsz6J9yC; Fri, 24 Nov 2023 01:44:04 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 23 Nov 2023 17:44:07 +0000 From: To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 05/11] cxl/memscrub: Add CXL device DDR5 ECS control feature Date: Fri, 24 Nov 2023 01:43:48 +0800 Message-ID: <20231123174355.1176-6-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20231123174355.1176-1-shiju.jose@huawei.com> References: <20231123174355.1176-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml100003.china.huawei.com (7.191.160.210) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: B2EA314001D X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: miuzj4zue85o3d9gdf7e9p4yc9gwxzgb X-HE-Tag: 1700761450-473114 X-HE-Meta: U2FsdGVkX18ln/JLVX3rANpLZiDTnZcRuZ99Mgh6AY1F3yiU26yZAM3hVJ2WP9qstXugfeylX35cKAXwy955SsFG5KErHt9myKNAy2Vn89SDoPy+o62IvvkW0TjHAXEbpQ9C5ns5SFtU4e43+VHJ5k7MjwOzi8Ep9GKV4bVO93ly4qwcfrJ34ztYGVl7hjj3ncfrX0tQlG45By+yyqg7VvT4CFf1Y8SqtkVZ+2kBX5J1OFNH3pcgOObO/Wb37Wd/fDQGjO91xV8e749YBhnWjcioy6owBGIELs+39X4f6Ozi8eGqep7bUlOVdzS3bJZ6gKpQr9ZRXpS+kvdvTkiZnkoNtw5lvEYSuer0KDm02vsI5ZmWoZAH8PycOx6d7uPCDb9QL8K8gFJUVKHtBHYKD7Zmj5t5+qsqV0Fh82ZWnCtzhWOVv1wRPzDraTErDGrFk/himcN9gDXsmidjeI5tIuIqiFkNlx7uHrCeu91XLw31jrUm+3phtmrDi8IyINZ91kCEXtNUYZkpb3taqn5GN+QNB3AUaFu+5mygoPIRR2pF+RMZ1qS8V2RdRG1WgsgrdHy8GUEimXAoRTlJEcMRZmBPbX7mz2DE9jXU1sYYjXOlXXBlYIEw4735v9v12+tu+atMV+1bjnlCr+GRTIlYHZzDLR22Jeex5U++2+3TtXpu/BcpH/KgLAFEpUemUUqvauHQcXWyhea7GmpFnHmRcUYjfIi5bPuYOWOay0cNjWey3d9gXgn4M2YIQr/JpMPjXD3VLobDcuxFD8l7HjmZsys6qBXtF2bPoAKE0hRkcOXuHwIjqMRfvksAIkmN/IcLV9E/1ekFW0dh+x1mvy6FSFtX55+RYdjkkK6EDf7LTcfW0W9uYfd0KqwCfFHdtjZ91xBL8ZHmNK6CHSrByZVeLHGwZP1nNLNYHUYdY8Kq6jmhUY29lhAT3xcHDG1bAvA6aGz+DSJMEZ8Qyakbq2O 6anTh6f3 lNbNp8FXmDDH15EcH0Xm5LM8dHIp0h0RHmqYynStDmi6SN+UZOOa+uz21e3d+65Y+Sm3tL9cz8pWgo3hn+TAwfFWI07YrG0dSoKFnaCArGDZ/AyxlnxwfqzrToKKFPt2lH2RCNHMxUOUNBuk5kUplmz3HTtqhnjCCCD7k0Or4pghim44MUSbTESp0Yuvs8A8FIqH9 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Shiju Jose CXL spec 3.1 section 8.2.9.9.11.2 describes the DDR5 Error Check Scrub (ECS) control feature. The Error Check Scrub (ECS) is a feature defined in JEDEC DDR5 SDRAM Specification (JESD79-5) and allows the DRAM to internally read, correct single-bit errors, and write back corrected data bits to the DRAM array while providing transparency to error counts. The ECS control feature allows the request to configure ECS input configurations during system boot or at run-time. The ECS control allows the requester to change the log entry type, the ECS threshold count provided that the request is within the definition specified in DDR5 mode registers, change mode between codeword mode and row count mode, and reset the ECS counter. Signed-off-by: Shiju Jose --- drivers/cxl/core/memscrub.c | 301 +++++++++++++++++++++++++++++++++++- drivers/cxl/cxlmem.h | 3 + drivers/cxl/pci.c | 1 + 3 files changed, 304 insertions(+), 1 deletion(-) diff --git a/drivers/cxl/core/memscrub.c b/drivers/cxl/core/memscrub.c index a74f4efa207e..7c58d56762b3 100644 --- a/drivers/cxl/core/memscrub.c +++ b/drivers/cxl/core/memscrub.c @@ -5,7 +5,7 @@ * Copyright (c) 2023 HiSilicon Limited. * * - Provides functions to configure patrol scrub - * feature of the CXL memory devices. + * and DDR5 ECS features of the CXL memory devices. */ #define pr_fmt(fmt) "CXL_MEM_SCRUB: " fmt @@ -264,3 +264,302 @@ int cxl_mem_patrol_scrub_init(struct cxl_memdev *cxlmd) return 0; } EXPORT_SYMBOL_NS_GPL(cxl_mem_patrol_scrub_init, CXL); + +/* CXL DDR5 ECS control definitions */ +#define CXL_MEMDEV_ECS_GET_FEAT_VERSION 0x01 +#define CXL_MEMDEV_ECS_SET_FEAT_VERSION 0x01 + +static const uuid_t cxl_ecs_uuid = + UUID_INIT(0xe5b13f22, 0x2328, 0x4a14, 0xb8, 0xba, 0xb9, 0x69, 0x1e, \ + 0x89, 0x33, 0x86); + +struct cxl_ecs_context { + struct device *dev; + u16 nregions; + u16 get_feat_size; + u16 set_feat_size; +}; + +/** + * struct cxl_memdev_ecs_params - CXL memory DDR5 ECS parameter data structure. + * @log_entry_type: ECS log entry type, per DRAM or per memory media FRU. + * @threshold: ECS threshold count per GB of memory cells. + * @mode: codeword/row count mode + * 0 : ECS counts rows with errors + * 1 : ECS counts codeword with errors + * @reset_counter: [IN] reset ECC counter to default value. + */ +struct cxl_memdev_ecs_params { + u8 log_entry_type; + u16 threshold; + u8 mode; + bool reset_counter; +}; + +enum { + CXL_MEMDEV_ECS_PARAM_LOG_ENTRY_TYPE = 0, + CXL_MEMDEV_ECS_PARAM_THRESHOLD, + CXL_MEMDEV_ECS_PARAM_MODE, + CXL_MEMDEV_ECS_PARAM_RESET_COUNTER, +}; + +#define CXL_MEMDEV_ECS_LOG_ENTRY_TYPE_MASK GENMASK(1, 0) +#define CXL_MEMDEV_ECS_REALTIME_REPORT_CAP_MASK BIT(0) +#define CXL_MEMDEV_ECS_THRESHOLD_COUNT_MASK GENMASK(2, 0) +#define CXL_MEMDEV_ECS_MODE_MASK BIT(3) +#define CXL_MEMDEV_ECS_RESET_COUNTER_MASK BIT(4) + +static const u16 ecs_supp_threshold[] = { 0, 0, 0, 256, 1024, 4096 }; + +enum { + ECS_LOG_ENTRY_TYPE_DRAM = 0x0, + ECS_LOG_ENTRY_TYPE_MEM_MEDIA_FRU = 0x1, +}; + +enum { + ECS_THRESHOLD_256 = 3, + ECS_THRESHOLD_1024 = 4, + ECS_THRESHOLD_4096 = 5, +}; + +enum { + ECS_MODE_COUNTS_ROWS = 0, + ECS_MODE_COUNTS_CODEWORDS = 1, +}; + +struct cxl_memdev_ecs_feat_read_attrbs { + u8 ecs_log_cap; + u8 ecs_cap; + __le16 ecs_config; + u8 ecs_flags; +} __packed; + +struct cxl_memdev_ecs_set_feat_pi { + struct cxl_mbox_set_feat_in pi; + struct cxl_memdev_ecs_feat_wr_attrbs { + u8 ecs_log_cap; + __le16 ecs_config; + } __packed wr_attrbs[]; +} __packed; + +/* CXL DDR5 ECS control functions */ +static int cxl_mem_ecs_get_attrbs(struct device *dev, int fru_id, + struct cxl_memdev_ecs_params *params) +{ + struct cxl_memdev_ecs_feat_read_attrbs *rd_attrbs __free(kvfree) = NULL; + struct cxl_memdev *cxlmd = to_cxl_memdev(dev->parent); + struct cxl_dev_state *cxlds = cxlmd->cxlds; + struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds); + struct cxl_mbox_get_feat_in pi = { + .uuid = cxl_ecs_uuid, + .offset = 0, + .selection = CXL_GET_FEAT_SEL_CURRENT_VALUE, + }; + struct cxl_ecs_context *cxl_ecs_ctx; + u8 threshold_index; + int ret; + + if (!mds) + return -EFAULT; + cxl_ecs_ctx = dev_get_drvdata(dev); + + pi.count = cxl_ecs_ctx->get_feat_size; + rd_attrbs = kvmalloc(pi.count, GFP_KERNEL); + if (!rd_attrbs) + return -ENOMEM; + + ret = cxl_get_feature(mds, &pi, rd_attrbs); + if (ret) { + params->log_entry_type = 0; + params->threshold = 0; + params->mode = 0; + return ret; + } + params->log_entry_type = FIELD_GET(CXL_MEMDEV_ECS_LOG_ENTRY_TYPE_MASK, + rd_attrbs[fru_id].ecs_log_cap); + threshold_index = FIELD_GET(CXL_MEMDEV_ECS_THRESHOLD_COUNT_MASK, + rd_attrbs[fru_id].ecs_config); + params->threshold = ecs_supp_threshold[threshold_index]; + params->mode = FIELD_GET(CXL_MEMDEV_ECS_MODE_MASK, + rd_attrbs[fru_id].ecs_config); + + return 0; +} + +static int __maybe_unused +cxl_mem_ecs_set_attrbs(struct device *dev, int fru_id, + struct cxl_memdev_ecs_params *params, u8 param_type) +{ + struct cxl_memdev_ecs_feat_read_attrbs *rd_attrbs __free(kvfree) = NULL; + struct cxl_memdev_ecs_set_feat_pi *set_pi __free(kvfree) = NULL; + struct cxl_memdev *cxlmd = to_cxl_memdev(dev->parent); + struct cxl_dev_state *cxlds = cxlmd->cxlds; + struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds); + struct cxl_mbox_get_feat_in pi = { + .uuid = cxl_ecs_uuid, + .offset = 0, + .selection = CXL_GET_FEAT_SEL_CURRENT_VALUE, + }; + struct cxl_memdev_ecs_feat_wr_attrbs *wr_attrbs; + struct cxl_memdev_ecs_params rd_params; + struct cxl_ecs_context *cxl_ecs_ctx; + u16 nmedia_frus, count; + u32 set_pi_size; + int ret; + + if (!mds) + return -EFAULT; + + cxl_ecs_ctx = dev_get_drvdata(dev); + nmedia_frus = cxl_ecs_ctx->nregions; + + rd_attrbs = kvmalloc(cxl_ecs_ctx->get_feat_size, GFP_KERNEL); + if (!rd_attrbs) + return -ENOMEM; + + pi.count = cxl_ecs_ctx->get_feat_size; + ret = cxl_get_feature(mds, &pi, rd_attrbs); + if (ret) + return ret; + set_pi_size = sizeof(struct cxl_mbox_set_feat_in) + + cxl_ecs_ctx->set_feat_size; + set_pi = kvmalloc(set_pi_size, GFP_KERNEL); + if (!set_pi) + return -ENOMEM; + + set_pi->pi.uuid = cxl_ecs_uuid; + set_pi->pi.flags = CXL_SET_FEAT_FLAG_MOD_VALUE_SAVED_ACROSS_RESET | + CXL_SET_FEAT_FLAG_FULL_DATA_TRANSFER; + set_pi->pi.offset = 0; + set_pi->pi.version = CXL_MEMDEV_ECS_SET_FEAT_VERSION; + /* Fill writable attributes from the current attributes read for all the media FRUs */ + wr_attrbs = set_pi->wr_attrbs; + for (count = 0; count < nmedia_frus; count++) { + wr_attrbs[count].ecs_log_cap = rd_attrbs[count].ecs_log_cap; + wr_attrbs[count].ecs_config = rd_attrbs[count].ecs_config; + } + + /* Fill attribute to be set for the media FRU */ + switch (param_type) { + case CXL_MEMDEV_ECS_PARAM_LOG_ENTRY_TYPE: + if (params->log_entry_type != ECS_LOG_ENTRY_TYPE_DRAM && + params->log_entry_type != ECS_LOG_ENTRY_TYPE_MEM_MEDIA_FRU) { + dev_err(dev->parent, + "Invalid CXL ECS scrub log entry type(%d) to set\n", + params->log_entry_type); + dev_err(dev->parent, + "Log Entry Type 0: per DRAM 1: per Memory Media FRU\n"); + return -EINVAL; + } + wr_attrbs[fru_id].ecs_log_cap = FIELD_PREP(CXL_MEMDEV_ECS_LOG_ENTRY_TYPE_MASK, + params->log_entry_type); + break; + case CXL_MEMDEV_ECS_PARAM_THRESHOLD: + wr_attrbs[fru_id].ecs_config &= ~CXL_MEMDEV_ECS_THRESHOLD_COUNT_MASK; + switch (params->threshold) { + case 256: + wr_attrbs[fru_id].ecs_config |= FIELD_PREP( + CXL_MEMDEV_ECS_THRESHOLD_COUNT_MASK, + ECS_THRESHOLD_256); + break; + case 1024: + wr_attrbs[fru_id].ecs_config |= FIELD_PREP( + CXL_MEMDEV_ECS_THRESHOLD_COUNT_MASK, + ECS_THRESHOLD_1024); + break; + case 4096: + wr_attrbs[fru_id].ecs_config |= FIELD_PREP( + CXL_MEMDEV_ECS_THRESHOLD_COUNT_MASK, + ECS_THRESHOLD_4096); + break; + default: + dev_err(dev->parent, + "Invalid CXL ECS scrub threshold count(%d) to set\n", + params->threshold); + dev_err(dev->parent, + "Supported scrub threshold count: 256,1024,4096\n"); + return -EINVAL; + } + break; + case CXL_MEMDEV_ECS_PARAM_MODE: + if (params->mode != ECS_MODE_COUNTS_ROWS && + params->mode != ECS_MODE_COUNTS_CODEWORDS) { + dev_err(dev->parent, + "Invalid CXL ECS scrub mode(%d) to set\n", + params->mode); + dev_err(dev->parent, + "Mode 0: ECS counts rows with errors" + " 1: ECS counts codewords with errors\n"); + return -EINVAL; + } + wr_attrbs[fru_id].ecs_config &= ~CXL_MEMDEV_ECS_MODE_MASK; + wr_attrbs[fru_id].ecs_config |= FIELD_PREP(CXL_MEMDEV_ECS_MODE_MASK, + params->mode); + break; + case CXL_MEMDEV_ECS_PARAM_RESET_COUNTER: + wr_attrbs[fru_id].ecs_config &= ~CXL_MEMDEV_ECS_RESET_COUNTER_MASK; + wr_attrbs[fru_id].ecs_config |= FIELD_PREP(CXL_MEMDEV_ECS_RESET_COUNTER_MASK, + params->reset_counter); + break; + default: + dev_err(dev->parent, "Invalid CXL ECS parameter to set\n"); + return -EINVAL; + } + ret = cxl_set_feature(mds, set_pi, set_pi_size); + if (ret) { + dev_err(dev->parent, "CXL ECS set feature fail ret=%d\n", ret); + return ret; + } + + /* Verify attribute is set successfully */ + ret = cxl_mem_ecs_get_attrbs(dev, fru_id, &rd_params); + if (ret) { + dev_err(dev->parent, "Get cxlmemdev ECS params fail ret=%d\n", ret); + return ret; + } + switch (param_type) { + case CXL_MEMDEV_ECS_PARAM_LOG_ENTRY_TYPE: + if (rd_params.log_entry_type != params->log_entry_type) + return -EFAULT; + break; + case CXL_MEMDEV_ECS_PARAM_THRESHOLD: + if (rd_params.threshold != params->threshold) + return -EFAULT; + break; + case CXL_MEMDEV_ECS_PARAM_MODE: + if (rd_params.mode != params->mode) + return -EFAULT; + break; + } + + return 0; +} + +int cxl_mem_ddr5_ecs_init(struct cxl_memdev *cxlmd) +{ + struct cxl_mbox_supp_feat_entry feat_entry; + struct cxl_ecs_context *cxl_ecs_ctx; + int nmedia_frus; + int ret; + + ret = cxl_mem_get_supported_feature_entry(cxlmd, &cxl_ecs_uuid, &feat_entry); + if (ret < 0) + return ret; + + if (!(feat_entry.attrb_flags & CXL_FEAT_ENTRY_FLAG_CHANGABLE)) + return -ENOTSUPP; + nmedia_frus = feat_entry.get_feat_size/ + sizeof(struct cxl_memdev_ecs_feat_read_attrbs); + if (nmedia_frus) { + cxl_ecs_ctx = devm_kzalloc(&cxlmd->dev, sizeof(*cxl_ecs_ctx), GFP_KERNEL); + if (!cxl_ecs_ctx) + return -ENOMEM; + + cxl_ecs_ctx->nregions = nmedia_frus; + cxl_ecs_ctx->get_feat_size = feat_entry.get_feat_size; + cxl_ecs_ctx->set_feat_size = feat_entry.set_feat_size; + } + + return 0; +} +EXPORT_SYMBOL_NS_GPL(cxl_mem_ddr5_ecs_init, CXL); diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 25c46e72af16..c704d5c28d0d 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -986,9 +986,12 @@ int cxl_clear_poison(struct cxl_memdev *cxlmd, u64 dpa); /* cxl memory scrub functions */ #ifdef CONFIG_CXL_SCRUB int cxl_mem_patrol_scrub_init(struct cxl_memdev *cxlmd); +int cxl_mem_ddr5_ecs_init(struct cxl_memdev *cxlmd); #else static inline int cxl_mem_patrol_scrub_init(struct cxl_memdev *cxlmd) { return -ENOTSUPP; } +static inline int cxl_mem_ddr5_ecs_init(struct cxl_memdev *cxlmd) +{ return -ENOTSUPP; } #endif #ifdef CONFIG_CXL_SUSPEND diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index acc337b8c365..433a6cba94df 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -885,6 +885,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) * Initialize optional CXL scrub features */ cxl_mem_patrol_scrub_init(cxlmd); + cxl_mem_ddr5_ecs_init(cxlmd); rc = devm_cxl_sanitize_setup_notifier(&pdev->dev, cxlmd); if (rc) From patchwork Thu Nov 23 17:43:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13466478 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DB44C624B4 for ; Thu, 23 Nov 2023 17:44:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DBC156B0684; Thu, 23 Nov 2023 12:44:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D1DA86B0685; Thu, 23 Nov 2023 12:44:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B48176B0686; Thu, 23 Nov 2023 12:44:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9F27E6B0684 for ; Thu, 23 Nov 2023 12:44:13 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 79C5DB6FEA for ; Thu, 23 Nov 2023 17:44:13 +0000 (UTC) X-FDA: 81489942786.01.EA87061 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf27.hostedemail.com (Postfix) with ESMTP id 6F0CD4001F for ; Thu, 23 Nov 2023 17:44:11 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf27.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700761451; a=rsa-sha256; cv=none; b=C/SJZqnWxrCmfb8HuU7rYMydjrUFkNvSSnbi5UaU2NxApTwpOjScSWbnbDHHQbvMdBGIve 5b5okfSVYIxfMKV1WjLOnTLO3kEn399xqDRxbiTrP1muwiSoheyPS09Ix9Ozm6zTEZtAKH sUgFcxMRKd0sjHH6HCccKnMwnUFI/LM= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf27.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700761451; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OynXFJlndwJXiEZGDJaAV8ry869CB/+WlGLouXkOgho=; b=2FHt8wLtrkVUogTa0cjfj6wFEPbscUJAIXs8k1EbM8hcrxWhVITcI1RXRhY6TKB3LTv2ea NBz/U8qcyyN/flLKwougOLv4nibmx+Dlusb/FHwigsQcl5GvB6Zn08SfBFc143nc+9tZzK esdbDxktoqUrKAU92FFf4fPTKerHZ1E= Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Sblps4H8Dz6JB04; Fri, 24 Nov 2023 01:44:05 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 23 Nov 2023 17:44:08 +0000 From: To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 06/11] memory: scrub: Add scrub driver supports configuring memory scrubs in the system Date: Fri, 24 Nov 2023 01:43:49 +0800 Message-ID: <20231123174355.1176-7-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20231123174355.1176-1-shiju.jose@huawei.com> References: <20231123174355.1176-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml100003.china.huawei.com (7.191.160.210) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 6F0CD4001F X-Stat-Signature: ur3pysjc5539qoy6apsp9z66isyc6ffb X-Rspam-User: X-HE-Tag: 1700761451-947800 X-HE-Meta: U2FsdGVkX1/r5SSGfVt32Rm2K+fYFYinlGMVnRifkJ0uP9BSCFcLP93rh1x26r47MUM3xnTpX/9B8i/4fHRRiDorhShAOuB6E1Gm7n2hlGJrWpVS42X4PB6Q6QyH3R1Rccg+LLKFd2GaUrDl50Zv8D2Tsr6JvgLzJGTDli799/Mwy0gmK7iup8KXbUQNeOxM+AzAYlvh4mfjFzLW5JybIQsLDI5eJGyZNbFlnvxbXfIKf17+b0ARRLeB4uznCL5wwDotI+aBolhIbNB3NUjfyZZG7kZBOckgWDZwL1Ax0XnLluh3Ig9d6abhxHxR1af9qyMFKKMBXkFmPI0ckw8QwBrY2uAIudnc+I6ZDTyA7V7VBhTBNVeEnk/Yj/uvZAHEnF06YbKzLC1Ply8upum+hwzo+PI7gBwUNt0rDmjVBKqZ4B2ME2XwcBkBjlwv8fmfDk+C9dTRvBiIzpZnizQVd79bWJrDpkNp9kdyoNGGNr7yH9whRBKFN9MVyJNl3YPZftUt4MrU6DXVvDw78/vEz2lAiQb3QHiL8TmqUrYujFO7MEJQqnMo4M8SIGGdZ+l+xPo9xm7+TnpIT9IShS5rqrZv8do5xfTEP9dHBE6xZXOBdCLEoGtuECRMZVvj+oghgrRHq7JLl94ZpZIKLqt5ksh9y4Nz0qZWgn+XGIh9X2KdCr8eszhYNzpKak0wzDdoNZsgCgcU7oIfSONqQ61yL4olSCHzHeRFfsHGdZJ18yOJNamEjFkQloExj0d/cTyv1MzrumfnPMq8zqSFgGkwV8W0fwnXqKmiTMKlayGLthiBvYgJkGYmceO0jtjgXquaY2INppO5/doRUS6+u6g0rz60uVqrG51dsiuPRX14Lgo8CWhFmStHTwgNpJ+mMEySqXMnKNaIZp5CJ04qVzwMlGDqpLBeqB1xL9PX254DSX8sXddtoZY5zP3hhhO0w/80IPHnwiV5TF0NUF+gCKF phOUjGpM r59sqHXRKWK3elVdiL5qrzT1bYMuHq9DPxkQluSNIttWqtIiFmyyacVbLhl5zeWibkdWVqnrixSRwlmGBN82aoj1q9HCXYER7yMaJv7XkFj+VpLOuClTZasI0ndbINMJEXt7JzMwUBuYLztA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Shiju Jose Add scrub driver supports configuring the memory scrubs in the system. The scrub driver provides the interface for registering the scrub devices and to configure the attributes of memory scrubs in the system. Driver exposes the scrub parameter attributes to the user via sysfs in /sys/class/scrub/scrubX/regionY/ This driver has been implemented referring to the hwmon subsystem. Signed-off-by: Shiju Jose --- drivers/memory/Kconfig | 1 + drivers/memory/Makefile | 1 + drivers/memory/scrub/Kconfig | 11 + drivers/memory/scrub/Makefile | 6 + drivers/memory/scrub/memory-scrub.c | 470 ++++++++++++++++++++++++++++ include/memory/memory-scrub.h | 80 +++++ 6 files changed, 569 insertions(+) create mode 100644 drivers/memory/scrub/Kconfig create mode 100644 drivers/memory/scrub/Makefile create mode 100755 drivers/memory/scrub/memory-scrub.c create mode 100755 include/memory/memory-scrub.h diff --git a/drivers/memory/Kconfig b/drivers/memory/Kconfig index 8efdd1f97139..d2e015c09d83 100644 --- a/drivers/memory/Kconfig +++ b/drivers/memory/Kconfig @@ -227,5 +227,6 @@ config STM32_FMC2_EBI source "drivers/memory/samsung/Kconfig" source "drivers/memory/tegra/Kconfig" +source "drivers/memory/scrub/Kconfig" endif diff --git a/drivers/memory/Makefile b/drivers/memory/Makefile index d2e6ca9abbe0..4b37312cb342 100644 --- a/drivers/memory/Makefile +++ b/drivers/memory/Makefile @@ -27,6 +27,7 @@ obj-$(CONFIG_STM32_FMC2_EBI) += stm32-fmc2-ebi.o obj-$(CONFIG_SAMSUNG_MC) += samsung/ obj-$(CONFIG_TEGRA_MC) += tegra/ +obj-$(CONFIG_SCRUB) += scrub/ obj-$(CONFIG_TI_EMIF_SRAM) += ti-emif-sram.o obj-$(CONFIG_FPGA_DFL_EMIF) += dfl-emif.o diff --git a/drivers/memory/scrub/Kconfig b/drivers/memory/scrub/Kconfig new file mode 100644 index 000000000000..fa7d68f53a69 --- /dev/null +++ b/drivers/memory/scrub/Kconfig @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Memory scrub driver configurations +# + +config SCRUB + bool "Memory scrub driver" + help + This option selects the memory scrub subsystem, supports + configuring the parameters of underlying scrubbers in the + system for the DRAM memories. diff --git a/drivers/memory/scrub/Makefile b/drivers/memory/scrub/Makefile new file mode 100644 index 000000000000..1b677132ca13 --- /dev/null +++ b/drivers/memory/scrub/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for memory scrub drivers +# + +obj-$(CONFIG_SCRUB) += memory-scrub.o diff --git a/drivers/memory/scrub/memory-scrub.c b/drivers/memory/scrub/memory-scrub.c new file mode 100755 index 000000000000..c2d794b2624b --- /dev/null +++ b/drivers/memory/scrub/memory-scrub.c @@ -0,0 +1,470 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Memory scrub controller driver support to configure + * the parameters of the memory scrubbers and enable. + * + * Copyright (c) 2023 HiSilicon Limited. + */ + +#define pr_fmt(fmt) "MEM SCRUB: " fmt + +#include +#include +#include +#include +#include +#include +#include + +/* memory scrubber config definitions */ +#define SCRUB_ID_PREFIX "scrub" +#define SCRUB_ID_FORMAT SCRUB_ID_PREFIX "%d" +#define SCRUB_DEV_MAX_NAME_LENGTH 128 + +static DEFINE_IDA(scrub_ida); + +struct scrub_device { + char name[SCRUB_DEV_MAX_NAME_LENGTH]; + int id; + struct device dev; + const struct scrub_source_info *source_info; + struct list_head tzdata; + char (*region_name)[]; + struct attribute_group group; + int ngroups; + struct attribute_group *region_groups; + const struct attribute_group **groups; +}; + +#define to_scrub_device(d) container_of(d, struct scrub_device, dev) +#define SCRUB_MAX_SYSFS_ATTR_NAME_LENGTH 64 + +struct scrub_device_attribute { + struct device_attribute dev_attr; + const struct scrub_ops *ops; + u32 attr; + int region_id; + char name[SCRUB_MAX_SYSFS_ATTR_NAME_LENGTH]; +}; + +#define to_scrub_attr(d) \ + container_of(d, struct scrub_device_attribute, dev_attr) +#define to_dev_attr(a) container_of(a, struct device_attribute, attr) + +static ssize_t name_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "%s\n", to_scrub_device(dev)->name); +} +static DEVICE_ATTR_RO(name); + +static struct attribute *scrub_dev_attrs[] = { + &dev_attr_name.attr, + NULL +}; + +static umode_t scrub_dev_attr_is_visible(struct kobject *kobj, + struct attribute *attr, int n) +{ + if (attr != &dev_attr_name.attr) + return 0; + + return attr->mode; +} + +static const struct attribute_group scrub_dev_attr_group = { + .attrs = scrub_dev_attrs, + .is_visible = scrub_dev_attr_is_visible, +}; + +static const struct attribute_group *scrub_dev_attr_groups[] = { + &scrub_dev_attr_group, + NULL +}; + +static void scrub_free_attrs(struct attribute **attrs) +{ + int i; + + for (i = 0; attrs[i]; i++) { + struct device_attribute *dattr = to_dev_attr(attrs[i]); + struct scrub_device_attribute *hattr = to_scrub_attr(dattr); + + kfree(hattr); + } + kfree(attrs); +} + +static void scrub_dev_release(struct device *dev) +{ + int count; + struct attribute_group *group; + struct scrub_device *scrub_dev = to_scrub_device(dev); + + for (count = 0; count < scrub_dev->ngroups; count++) { + group = (struct attribute_group *)scrub_dev->groups[count]; + if (group) + scrub_free_attrs(group->attrs); + } + kfree(scrub_dev->region_name); + kfree(scrub_dev->region_groups); + kfree(scrub_dev->groups); + ida_free(&scrub_ida, scrub_dev->id); + kfree(scrub_dev); +} + +static struct class scrub_class = { + .name = "scrub", + .dev_groups = scrub_dev_attr_groups, + .dev_release = scrub_dev_release, +}; + +/* sysfs attribute management */ + +static ssize_t scrub_attr_show(struct device *dev, + struct device_attribute *devattr, char *buf) +{ + int ret; + u64 val; + struct scrub_device_attribute *hattr = to_scrub_attr(devattr); + + ret = hattr->ops->read(dev, hattr->attr, hattr->region_id, &val); + if (ret < 0) + return ret; + + return sprintf(buf, "%lld\n", val); +} + +static ssize_t scrub_attr_show_hex(struct device *dev, + struct device_attribute *devattr, char *buf) +{ + int ret; + u64 val; + struct scrub_device_attribute *hattr = to_scrub_attr(devattr); + + ret = hattr->ops->read(dev, hattr->attr, hattr->region_id, &val); + if (ret < 0) + return ret; + + return sprintf(buf, "0x%llx\n", val); +} + +static ssize_t scrub_attr_show_string(struct device *dev, + struct device_attribute *devattr, + char *buf) +{ + int ret; + struct scrub_device_attribute *hattr = to_scrub_attr(devattr); + + ret = hattr->ops->read_string(dev, hattr->attr, hattr->region_id, buf); + if (ret < 0) + return ret; + + return strlen(buf); +} + +static ssize_t scrub_attr_store(struct device *dev, + struct device_attribute *devattr, + const char *buf, size_t count) +{ + int ret; + long val; + struct scrub_device_attribute *hattr = to_scrub_attr(devattr); + + ret = kstrtol(buf, 10, &val); + if (ret < 0) + return ret; + + ret = hattr->ops->write(dev, hattr->attr, hattr->region_id, val); + if (ret < 0) + return ret; + + return count; +} + +static ssize_t scrub_attr_store_hex(struct device *dev, + struct device_attribute *devattr, + const char *buf, size_t count) +{ + int ret; + u64 val; + struct scrub_device_attribute *hattr = to_scrub_attr(devattr); + + ret = kstrtou64(buf, 16, &val); + if (ret < 0) + return ret; + + ret = hattr->ops->write(dev, hattr->attr, hattr->region_id, val); + if (ret < 0) + return ret; + + return count; +} + +static bool is_hex_attr(u32 attr) +{ + return (attr == scrub_addr_base) || + (attr == scrub_addr_size); +} + +static bool is_string_attr(u32 attr) +{ + return attr == scrub_speed_available; +} + +static struct attribute *scrub_genattr(const void *drvdata, + u32 attr, + const char *attrb_name, + const struct scrub_ops *ops, + int region_id) +{ + umode_t mode; + struct attribute *a; + struct device_attribute *dattr; + bool is_hex = is_hex_attr(attr); + struct scrub_device_attribute *hattr; + bool is_string = is_string_attr(attr); + + /* The attribute is invisible if there is no template string */ + if (!attrb_name) + return ERR_PTR(-ENOENT); + + mode = ops->is_visible(drvdata, attr, region_id); + if (!mode) + return ERR_PTR(-ENOENT); + + if ((mode & 0444) && ((is_string && !ops->read_string) || + (!is_string && !ops->read))) + return ERR_PTR(-EINVAL); + if ((mode & 0222) && (!ops->write)) + return ERR_PTR(-EINVAL); + + hattr = kzalloc(sizeof(*hattr), GFP_KERNEL); + if (!hattr) + return ERR_PTR(-ENOMEM); + + hattr->attr = attr; + hattr->ops = ops; + hattr->region_id = region_id; + + dattr = &hattr->dev_attr; + if (is_string) { + dattr->show = scrub_attr_show_string; + } else { + dattr->show = is_hex ? scrub_attr_show_hex : scrub_attr_show; + dattr->store = is_hex ? scrub_attr_store_hex : scrub_attr_store; + } + + a = &dattr->attr; + sysfs_attr_init(a); + a->name = attrb_name; + a->mode = mode; + + return a; +} + +static const char * const scrub_common_attrs[] = { + /* scrub attributes - common */ + [scrub_addr_base] = "addr_base", + [scrub_addr_size] = "addr_size", + [scrub_enable] = "enable", + [scrub_speed] = "speed", + [scrub_speed_available] = "speed_available", +}; + +static struct attribute ** +scrub_create_attrs(const void *drvdata, const struct scrub_ops *ops, int region_id) +{ + u32 attr; + int aindex = 0; + struct attribute *a; + struct attribute **attrs; + + attrs = kcalloc(max_attrs, sizeof(*attrs), GFP_KERNEL); + if (!attrs) + return ERR_PTR(-ENOMEM); + + for (attr = 0; attr < max_attrs; attr++) { + a = scrub_genattr(drvdata, attr, scrub_common_attrs[attr], + ops, region_id); + if (IS_ERR(a)) { + if (PTR_ERR(a) != -ENOENT) { + scrub_free_attrs(attrs); + return ERR_PTR(PTR_ERR(a)); + } + continue; + } + attrs[aindex++] = a; + } + + return attrs; +} + +static struct device * +scrub_device_register(struct device *dev, const char *name, void *drvdata, + const struct scrub_ops *ops, + int nregions) +{ + struct device *hdev; + struct attribute **attrs; + int err, count, region_id; + struct attribute_group *group; + struct scrub_device *scrub_dev; + char (*region_name)[SCRUB_MAX_SYSFS_ATTR_NAME_LENGTH]; + + scrub_dev = kzalloc(sizeof(*scrub_dev), GFP_KERNEL); + if (!scrub_dev) + return ERR_PTR(-ENOMEM); + hdev = &scrub_dev->dev; + + scrub_dev->id = ida_alloc(&scrub_ida, GFP_KERNEL); + if (scrub_dev->id < 0) { + err = -ENOMEM; + goto free_scrub_dev; + } + int ngroups = 2; /* terminating NULL plus &scrub_dev->groups */ + + ngroups += nregions; + + scrub_dev->groups = kcalloc(ngroups, sizeof(struct attribute_group *), GFP_KERNEL); + if (!scrub_dev->groups) { + err = -ENOMEM; + goto free_ida; + } + + if (nregions) { + scrub_dev->region_groups = kcalloc(nregions, sizeof(struct attribute_group), + GFP_KERNEL); + if (!scrub_dev->groups) { + err = -ENOMEM; + goto free_groups; + } + scrub_dev->region_name = kcalloc(nregions, SCRUB_MAX_SYSFS_ATTR_NAME_LENGTH, + GFP_KERNEL); + if (!scrub_dev->region_name) { + err = -ENOMEM; + goto free_region_groups; + } + } + + ngroups = 0; + scrub_dev->ngroups = 0; + if (nregions) { + region_name = scrub_dev->region_name; + for (region_id = 0; region_id < nregions; region_id++) { + attrs = scrub_create_attrs(drvdata, ops, region_id); + if (IS_ERR(attrs)) { + err = PTR_ERR(attrs); + goto free_attrs; + } + snprintf((char *)region_name, SCRUB_MAX_SYSFS_ATTR_NAME_LENGTH, + "region%d", region_id); + scrub_dev->region_groups[region_id].name = (char *)region_name; + scrub_dev->region_groups[region_id].attrs = attrs; + region_name++; + scrub_dev->groups[ngroups++] = &scrub_dev->region_groups[region_id]; + scrub_dev->ngroups = ngroups; + } + } else { + attrs = scrub_create_attrs(drvdata, ops, -1); + if (IS_ERR(attrs)) { + err = PTR_ERR(attrs); + goto free_region_name; + } + scrub_dev->group.attrs = attrs; + scrub_dev->groups[ngroups++] = &scrub_dev->group; + scrub_dev->ngroups = ngroups; + } + + hdev->groups = scrub_dev->groups; + hdev->class = &scrub_class; + hdev->parent = dev; + dev_set_drvdata(hdev, drvdata); + dev_set_name(hdev, SCRUB_ID_FORMAT, scrub_dev->id); + snprintf(scrub_dev->name, SCRUB_DEV_MAX_NAME_LENGTH, "%s", name); + err = device_register(hdev); + if (err) { + put_device(hdev); + return ERR_PTR(err); + } + + return hdev; + +free_attrs: + for (count = 0; count < scrub_dev->ngroups; count++) { + group = (struct attribute_group *)scrub_dev->groups[count]; + if (group) + scrub_free_attrs(group->attrs); + } + +free_region_name: + kfree(scrub_dev->region_name); + +free_region_groups: + kfree(scrub_dev->region_groups); + +free_groups: + kfree(scrub_dev->groups); + +free_ida: + ida_free(&scrub_ida, scrub_dev->id); + +free_scrub_dev: + kfree(scrub_dev); + return ERR_PTR(err); +} + +static void devm_scrub_release(void *dev) +{ + struct device *hdev = dev; + + device_unregister(hdev); +} + +/** + * devm_scrub_device_register - register hw scrubber device + * @dev: the parent device (mandatory) + * @name: hw scrubber name attribute (mandatory) + * @drvdata: driver data to attach to created device (mandatory) + * @ops: pointer to scrub_ops structure (mandatory) + * @nregions: number of scrub regions to create (optional) + * + * Returns the pointer to the new device. The new device is automatically + * unregistered with the parent device. + */ +struct device * +devm_scrub_device_register(struct device *dev, const char *name, + void *drvdata, + const struct scrub_ops *ops, + int nregions) +{ + struct device *hdev; + int ret; + + if (!dev || !name || !ops) + return ERR_PTR(-EINVAL); + + hdev = scrub_device_register(dev, name, drvdata, ops, nregions); + if (IS_ERR(hdev)) + return hdev; + + ret = devm_add_action_or_reset(dev, devm_scrub_release, hdev); + if (ret) + return ERR_PTR(ret); + + return hdev; +} +EXPORT_SYMBOL_GPL(devm_scrub_device_register); + +static int __init memory_scrub_control_init(void) +{ + int err; + + err = class_register(&scrub_class); + if (err) { + pr_err("couldn't register memory scrub control sysfs class\n"); + return err; + } + + return 0; +} +subsys_initcall(memory_scrub_control_init); diff --git a/include/memory/memory-scrub.h b/include/memory/memory-scrub.h new file mode 100755 index 000000000000..d7cbde4718d0 --- /dev/null +++ b/include/memory/memory-scrub.h @@ -0,0 +1,80 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Memory scrub controller driver support to configure + * the parameters of the memory scrubbers and enable. + * + * Copyright (c) 2023 HiSilicon Limited. + */ + +#ifndef __MEMORY_SCRUB_H +#define __MEMORY_SCRUB_H + +#include + +enum scrub_types { + scrub_common, + scrub_max, +}; + +enum scrub_attributes { + /* scrub attributes - common */ + scrub_addr_base, + scrub_addr_size, + scrub_enable, + scrub_speed, + scrub_speed_available, + max_attrs, +}; + +/** + * struct scrub_ops - scrub device operations + * @is_visible: Callback to return attribute visibility. Mandatory. + * Parameters are: + * @drvdata: + * pointer to driver-private data structure passed + * as argument to scrub_device_register(). + * @attr: scrubber attribute + * @region_id: + * memory region id + * The function returns the file permissions. + * If the return value is 0, no attribute will be created. + * @read: Read callback for data attributes. Mandatory if readable + * data attributes are present. + * Parameters are: + * @dev: pointer to hardware scrub device + * @attr: scrubber attribute + * @region_id: + * memory region id + * @val: pointer to returned value + * The function returns 0 on success or a negative error number. + * @read_string: Read callback for string attributes. Mandatory if string + * attributes are present. + * Parameters are: + * @dev: pointer to hardware scrub device + * @attr: scrubber attribute + * @region_id: + * memory region id + * @buf: pointer to buffer to copy string + * The function returns 0 on success or a negative error number. + * @write: Write callback for data attributes. Mandatory if writeable + * data attributes are present. + * Parameters are: + * @dev: pointer to hardware scrub device + * @attr: scrubber attribute + * @region_id: + * memory region id + * @val: value to write + * The function returns 0 on success or a negative error number. + */ +struct scrub_ops { + umode_t (*is_visible)(const void *drvdata, u32 attr, int region_id); + int (*read)(struct device *dev, u32 attr, int region_id, u64 *val); + int (*read_string)(struct device *dev, u32 attr, int region_id, char *buf); + int (*write)(struct device *dev, u32 attr, int region_id, u64 val); +}; + +struct device * +devm_scrub_device_register(struct device *dev, const char *name, + void *drvdata, const struct scrub_ops *ops, + int nregions); +#endif /* __MEMORY_SCRUB_H */ From patchwork Thu Nov 23 17:43:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13466479 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32C9EC61D97 for ; Thu, 23 Nov 2023 17:44:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2229A6B0686; Thu, 23 Nov 2023 12:44:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D5056B0687; Thu, 23 Nov 2023 12:44:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09CDA6B0688; Thu, 23 Nov 2023 12:44:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E9D456B0686 for ; Thu, 23 Nov 2023 12:44:14 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B8D2F81885 for ; Thu, 23 Nov 2023 17:44:14 +0000 (UTC) X-FDA: 81489942828.14.A70A140 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf15.hostedemail.com (Postfix) with ESMTP id AE764A001B for ; Thu, 23 Nov 2023 17:44:12 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700761453; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wZJi/TDA0l1UAWj0zGAseIzAOelDMaNCC2erp5shhdA=; b=A9AXLDmmqm/KvV5tN1hnQvbB7QeHhr339Z7Br3UuAaEU639j6daXHHfV17gZZvIQk/W+W9 K4rrWzAzPApz5H3s4bPa7TGyZnPkizpZGB/pstmY6QGQzBaquF8EePQEPbEVxZCatHMoMZ c/iinFR3QzTu19NyUkM2dYULLGE1X0Q= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700761453; a=rsa-sha256; cv=none; b=Q+pPeBiSHiaeDS5VVHRF3rukDMcB80kP3ERy0Mnh1efOCRqv372qI6cyDPHpHVDd7wG62q 7IC2/2raf1lJJkVSrGNQv5g6rgik4xIRPDxhuG5yKCA+elteIt+3Fs0TawN8bQAfuDlB+I 5X/qFQXzp0NDn0X522X2DKRKj8pWFIg= Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4SblnJ4VNMz6K8sP; Fri, 24 Nov 2023 01:42:44 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 23 Nov 2023 17:44:09 +0000 From: To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 07/11] cxl/memscrub: Register CXL device patrol scrub with scrub configure driver Date: Fri, 24 Nov 2023 01:43:50 +0800 Message-ID: <20231123174355.1176-8-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20231123174355.1176-1-shiju.jose@huawei.com> References: <20231123174355.1176-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml100003.china.huawei.com (7.191.160.210) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: AE764A001B X-Rspam-User: X-Stat-Signature: qnuet1kzu6m14yz4oq8w3ubgfouqtybp X-Rspamd-Server: rspam01 X-HE-Tag: 1700761452-5520 X-HE-Meta: U2FsdGVkX1+nVOoYHZjZ12CD9M7hw4VJtYoZ7CDuwLlgBruY+u5/selwB/teoIuu7mQll7wymgWRD8G5e2MtHoz/OlUJTklngDAuOo8ifguDMyxlXutsaVdn7TG1LTN3e2dtk9rACfYgynk0l9M5qYCM3y1bK2vKyGuTMeCrl0Xl7NuXOj57Q3mEFRmu96lJ7X99iQebbNAJNJQnPoC4tWjVS1xp21lpk/NwlQknF/8s1oBexd/rEQ1tGNcT3OfzohdKTwKtfjc6twQYrWcAjCtr24T/wH0cNw/egn4IypDh3zQ22+gtc1iFCjCn86jY/G8IGyQYO9lk/AtcIvKeXSLuFDSgKmlZN1vTReOjqx1kXMc6vPtR00LW65Hvky3ekeTDjkB8fS2pnylf5Q0VjO+bpSzX+5vJIydVQH4T2LgoEMrU9yqnwAolrnxHHjjByrIUh0gLp6pBlphATDrStqDBks3d9+HyxQypB2mePWefjmndLV3duzhiV6Eqa4rVAFnxxSnFLU2GmmopUpnBXgOfwGTR7hD18BRFz1gcZDDFB3INrbOmml/Rq0dcDWBCLNBI3gDgXQxuS3I4mwBhePgzghulUDyo+bIv2ZGe1LYPY8b2+B6mQcpLw2sQlfbAM6R/+1L1G8AIeVe6igM5JsnWPX9rSCVahYYEwr2g6M+lXvZMGbKpPYZ4F6Hui4Qy85qxcxPuxS2sL8P1SYZznir6JrCWcTo3Z/isYU52PqX9e6kd8LHjua11hJUyAI1SjgNacyYEk7mMlggJDFsYKLOCVw8athp07NsDedb+Gd4TeDrNwJYgewdFAyX9Y4F7c3HMY2PcVG0jKyJ4LI3CoBsXbngfkps/Z4InVae1/IhbafryV4YS63b18PNgT51Zw56fceYr7lYuIuAX8Gt4+8WX5zid3/6wXpXgfDC4CwqPK0SKeCQXiL9Lm75Wf2bP2HdS45JQltdQ1uLdf67 5FKiwDj9 l8iNrbkxLiWI7dYn86wZUbFTo7gPjInxcxFKbIIl99koQ2dr8lMxKvRpohoFMAPxTmF7p5nT4bnPa4XYKsVG4WGeUvY1hGWXSYBeNkFZI/u0s8mAt8Re9YFa5zmti/GDJwmREM0E2PdACXAI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Shiju Jose Register with the scrub configure driver to expose the sysfs attributes to the user for configuring the CXL device memory patrol scrub. Add the callback functions to support configuring the CXL memory device patrol scrub. Signed-off-by: Shiju Jose --- drivers/cxl/Kconfig | 6 ++ drivers/cxl/core/memscrub.c | 197 +++++++++++++++++++++++++++++++++++- 2 files changed, 200 insertions(+), 3 deletions(-) diff --git a/drivers/cxl/Kconfig b/drivers/cxl/Kconfig index 67d88f9bf52b..964b5f789770 100644 --- a/drivers/cxl/Kconfig +++ b/drivers/cxl/Kconfig @@ -159,11 +159,17 @@ config CXL_SCRUB bool "CXL: Memory scrub feature" depends on CXL_PCI depends on CXL_MEM + depends on SCRUB help The CXL memory scrub control is an optional feature allows host to control the scrub configurations of CXL Type 3 devices, which support patrol scrub and/or DDR5 ECS(Error Check Scrub). + Register with the scrub configure driver to expose sysfs attributes + to the user for configuring the CXL device memory patrol and DDR5 ECS + scrubs. Provides the interface functions to support configuring the + CXL memory device patrol and ECS scrubs. + Say 'y/n' to enable/disable the CXL memory scrub driver that will attach to CXL.mem devices for memory scrub control feature. See sections 8.2.9.9.11.1 and 8.2.9.9.11.2 in the CXL 3.1 specification diff --git a/drivers/cxl/core/memscrub.c b/drivers/cxl/core/memscrub.c index 7c58d56762b3..c09f9fa5044a 100644 --- a/drivers/cxl/core/memscrub.c +++ b/drivers/cxl/core/memscrub.c @@ -6,14 +6,19 @@ * * - Provides functions to configure patrol scrub * and DDR5 ECS features of the CXL memory devices. + * - Registers with the scrub driver to expose + * the sysfs attributes to the user for configuring + * the memory patrol scrub and DDR5 ECS features. */ #define pr_fmt(fmt) "CXL_MEM_SCRUB: " fmt #include +#include /* CXL memory scrub feature common definitions */ #define CXL_SCRUB_MAX_ATTRB_RANGE_LENGTH 128 +#define CXL_MEMDEV_MAX_NAME_LENGTH 128 static int cxl_mem_get_supported_feature_entry(struct cxl_memdev *cxlmd, const uuid_t *feat_uuid, struct cxl_mbox_supp_feat_entry *feat_entry_out) @@ -63,6 +68,16 @@ static int cxl_mem_get_supported_feature_entry(struct cxl_memdev *cxlmd, const u #define CXL_MEMDEV_PS_GET_FEAT_VERSION 0x01 #define CXL_MEMDEV_PS_SET_FEAT_VERSION 0x01 +#define CXL_PATROL_SCRUB "cxl_patrol_scrub" + +/* The default number of regions for CXL memory device patrol scrubber + * Patrol scrub is a feature where the device controller scrubs the + * memory at a regular interval accroding to the CXL specification. + * Hence the number of memory regions to scrub assosiated to the patrol + * scrub is 1. + */ +#define CXL_MEMDEV_PATROL_SCRUB_NUM_REGIONS 1 + static const uuid_t cxl_patrol_scrub_uuid = UUID_INIT(0x96dad7d6, 0xfde8, 0x482b, 0xa7, 0x33, 0x75, 0x77, 0x4e, \ 0x06, 0xdb, 0x8a); @@ -159,9 +174,8 @@ static int cxl_mem_ps_get_attrbs(struct device *dev, return 0; } -static int __maybe_unused -cxl_mem_ps_set_attrbs(struct device *dev, struct cxl_memdev_ps_params *params, - u8 param_type) +static int cxl_mem_ps_set_attrbs(struct device *dev, + struct cxl_memdev_ps_params *params, u8 param_type) { struct cxl_memdev_ps_set_feat_pi set_pi = { .pi.uuid = cxl_patrol_scrub_uuid, @@ -232,11 +246,180 @@ cxl_mem_ps_set_attrbs(struct device *dev, struct cxl_memdev_ps_params *params, return 0; } +static int cxl_mem_ps_enable_write(struct device *dev, long val) +{ + struct cxl_memdev_ps_params params; + int ret; + + params.enable = val; + ret = cxl_mem_ps_set_attrbs(dev, ¶ms, CXL_MEMDEV_PS_PARAM_ENABLE); + if (ret) { + dev_err(dev, "CXL patrol scrub enable fail, enable=%d ret=%d\n", + params.enable, ret); + return ret; + } + + return 0; +} + +static int cxl_mem_ps_speed_read(struct device *dev, u64 *val) +{ + struct cxl_memdev_ps_params params; + int ret; + + ret = cxl_mem_ps_get_attrbs(dev, ¶ms); + if (ret) { + dev_err(dev, "Get CXL patrol scrub params fail ret=%d\n", + ret); + return ret; + } + *val = params.speed; + + return 0; +} + +static int cxl_mem_ps_speed_write(struct device *dev, long val) +{ + struct cxl_memdev_ps_params params; + int ret; + + params.speed = val; + ret = cxl_mem_ps_set_attrbs(dev, ¶ms, CXL_MEMDEV_PS_PARAM_SPEED); + if (ret) { + dev_err(dev, "Set CXL patrol scrub params for speed fail ret=%d\n", + ret); + return ret; + } + + return 0; +} + +static int cxl_mem_ps_speed_available_read(struct device *dev, char *buf) +{ + struct cxl_memdev_ps_params params; + int ret; + + ret = cxl_mem_ps_get_attrbs(dev, ¶ms); + if (ret) { + dev_err(dev, "Get CXL patrol scrub params fail ret=%d\n", + ret); + return ret; + } + + sysfs_emit(buf, "%s\n", params.speed_avail); + + return 0; +} + +/** + * cxl_mem_patrol_scrub_is_visible() - Callback to return attribute visibility + * @drv_data: Pointer to driver-private data structure passed + * as argument to devm_scrub_device_register(). + * @attr: Scrub attribute + * @region_id: ID of the memory region + * + * Returns: 0 on success, an error otherwise + */ +static umode_t cxl_mem_patrol_scrub_is_visible(const void *drv_data, + u32 attr, int region_id) +{ + const struct cxl_patrol_scrub_context *cxl_ps_ctx = drv_data; + + if (attr == scrub_speed_available || + attr == scrub_speed) { + if (!cxl_ps_ctx->scrub_cycle_changeable) + return 0; + } + + switch (attr) { + case scrub_speed_available: + return 0444; + case scrub_enable: + return 0200; + case scrub_speed: + return 0644; + default: + return 0; + } +} + +/** + * cxl_mem_patrol_scrub_read() - Read callback for data attributes + * @dev: Pointer to scrub device + * @attr: Scrub attribute + * @region_id: ID of the memory region + * @val: Pointer to the returned data + * + * Returns: 0 on success, an error otherwise + */ +static int cxl_mem_patrol_scrub_read(struct device *dev, u32 attr, + int region_id, u64 *val) +{ + + switch (attr) { + case scrub_speed: + return cxl_mem_ps_speed_read(dev->parent, val); + default: + return -ENOTSUPP; + } +} + +/** + * cxl_mem_patrol_scrub_write() - Write callback for data attributes + * @dev: Pointer to scrub device + * @attr: Scrub attribute + * @region_id: ID of the memory region + * @val: Value to write + * + * Returns: 0 on success, an error otherwise + */ +static int cxl_mem_patrol_scrub_write(struct device *dev, u32 attr, + int region_id, u64 val) +{ + switch (attr) { + case scrub_enable: + return cxl_mem_ps_enable_write(dev->parent, val); + case scrub_speed: + return cxl_mem_ps_speed_write(dev->parent, val); + default: + return -ENOTSUPP; + } +} + +/** + * cxl_mem_patrol_scrub_read_strings() - Read callback for string attributes + * @dev: Pointer to scrub device + * @attr: Scrub attribute + * @region_id: ID of the memory region + * @buf: Pointer to the buffer for copying returned string + * + * Returns: 0 on success, an error otherwise + */ +static int cxl_mem_patrol_scrub_read_strings(struct device *dev, u32 attr, + int region_id, char *buf) +{ + switch (attr) { + case scrub_speed_available: + return cxl_mem_ps_speed_available_read(dev->parent, buf); + default: + return -ENOTSUPP; + } +} + +static const struct scrub_ops cxl_ps_scrub_ops = { + .is_visible = cxl_mem_patrol_scrub_is_visible, + .read = cxl_mem_patrol_scrub_read, + .write = cxl_mem_patrol_scrub_write, + .read_string = cxl_mem_patrol_scrub_read_strings, +}; + int cxl_mem_patrol_scrub_init(struct cxl_memdev *cxlmd) { + char scrub_name[CXL_MEMDEV_MAX_NAME_LENGTH]; struct cxl_patrol_scrub_context *cxl_ps_ctx; struct cxl_mbox_supp_feat_entry feat_entry; struct cxl_memdev_ps_params params; + struct device *cxl_scrub_dev; int ret; ret = cxl_mem_get_supported_feature_entry(cxlmd, &cxl_patrol_scrub_uuid, @@ -261,6 +444,14 @@ int cxl_mem_patrol_scrub_init(struct cxl_memdev *cxlmd) } cxl_ps_ctx->scrub_cycle_changeable = params.scrub_cycle_changeable; + snprintf(scrub_name, sizeof(scrub_name), "%s_%s", + CXL_PATROL_SCRUB, dev_name(&cxlmd->dev)); + cxl_scrub_dev = devm_scrub_device_register(&cxlmd->dev, scrub_name, + cxl_ps_ctx, &cxl_ps_scrub_ops, + CXL_MEMDEV_PATROL_SCRUB_NUM_REGIONS); + if (IS_ERR(cxl_scrub_dev)) + return PTR_ERR(cxl_scrub_dev); + return 0; } EXPORT_SYMBOL_NS_GPL(cxl_mem_patrol_scrub_init, CXL); From patchwork Thu Nov 23 17:43:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13466480 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4599C624B4 for ; Thu, 23 Nov 2023 17:44:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E7FD66B0687; Thu, 23 Nov 2023 12:44:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E558A6B0688; Thu, 23 Nov 2023 12:44:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C5A666B0689; Thu, 23 Nov 2023 12:44:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B13926B0687 for ; Thu, 23 Nov 2023 12:44:15 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 925081A1448 for ; Thu, 23 Nov 2023 17:44:15 +0000 (UTC) X-FDA: 81489942870.03.CF0CA5C Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf03.hostedemail.com (Postfix) with ESMTP id 8C0442000F for ; Thu, 23 Nov 2023 17:44:13 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf03.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700761453; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qBl6X781g1URePy/zIT03Qx96CWSeuENJeyyONXt9xs=; b=8BLRi2rzQISNEyphqmFIB3J2UxtTKzIcNPZJwYci1eYIyhiLV8ffOMfowyLPNV3Ag+me80 mlxsKShk1k0lQXcOZLCabRVbIXIHdNhtVj1IuDYM4ywbg0ZHdvBSHFdA9s5aXYfOBnC4Lb skpf1xB5mfUeZI3PYsxKZZa0wicn88s= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf03.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700761453; a=rsa-sha256; cv=none; b=78MNxDAxtXGaMaLYOuKATOGkY8DppZ9gpHnP4NxhlukxFXY1MT6jETvDZ9ZRXaaiUVZXP9 RDkq3hpEO0ntNje3c6cmyDegz78ta0Gpf3+an1uqrQ/YAe2IVgand2jiALw/s7XX3xS9qA HTsKkPCXiE/cgC00SDuOunMaDGcdQVc= Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4SblnK1kn3z6K8sc; Fri, 24 Nov 2023 01:42:45 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 23 Nov 2023 17:44:10 +0000 From: To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 08/11] memory: scrub: Add scrub control attributes for the DDR5 ECS Date: Fri, 24 Nov 2023 01:43:51 +0800 Message-ID: <20231123174355.1176-9-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20231123174355.1176-1-shiju.jose@huawei.com> References: <20231123174355.1176-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml100003.china.huawei.com (7.191.160.210) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 8C0442000F X-Stat-Signature: 56kq5pdx7p96xd3rg5yu7d8khz3kb71z X-HE-Tag: 1700761453-676902 X-HE-Meta: U2FsdGVkX19+r50NqSVXwvlZvWV41nLSm/Zc+3kA+owE7XKf+ese1qHA5LyDw/0T9q3rDylJhQLkatXpX74qnzlI7BRojFTA1LlKRkjojwq9ZzU89DsbbB2cmXZEO/5ytKV4f8D1G56pvVpkom590dY27gZCnd4dGoHWyAm7YMiaox9cH+hU0Ca+65iggsVJnvaXvEn0km9YLq926Zp6GHdiMi+6Qpy+t0NIpqHpZkcM3E3AtCXFCwNAreU79gpt/t9HaOQxOX69q3Xpzq4WplFbI+VarxkP6D5y2aHmoKikMy0FnCpFUaRSYzUyb7VUqZsZutNeeK7Obb47U8fLbKX3m7eRF60QAdTpXPnNLt8V9WGjq8do4/gVjcNQfHsl/uUOrkeJG3g+z0ZZTt++DBLj2ySWa/0Sev+LrFrxp0z+gQ0m35cX6lX8IylTeiec4uxnjTf9haJynsOs4L9kA8dYqTWnuCvkQMUUeEmxL/j+N5pDjU25v/4usQ6ijY2GJUj1fYbkogkn5FcuM59I2fqnkBK2kPnqmPu/IG0nFevOzX6uLnyaSf3W3xdzfnf3a7iu0faIK7aTweZoXOfQ1TqJE8mNsdgwOxjMvcfzVh/uau6mTiQ7Nw1JvEfBDlb0s0pCOQBnLSTOJjwmROoNtiURknvRjcTEnFh9hjS++t6oQa6yYi0Ux7vOyPZa8FwmQsWyKj0t2YK1oOJxBrOBUI+K2y05ZOgjEi4C6sjoAq4xOavDkGmiTmblNiyBbiimUE5u06y3DvXZNwEKHYi+xt8PtbdtL8qMRUu7Buu4PF7Ffze4dLfcKG3m2zN+kJCvVoGT187JA/L4tas4qS6/K0Fr+k5jX8XEdCNiiuAxCNbR/9QnnoFcvkwxtvVkKvf2DXXykl8YlAAuECN30hn9LPxkHRCGKCPrxyxp6ME3U/8GTYnoTo8drTj765kFd3n06T+UDtIaaMJ6+roNQol poxCu9hE U4dgy9Q/Qz4HGiyoWq9FCluKpzXK3URB30sWOQedwLslw03oPIkuO/SIYWVLx4VGGemp7hWUMgy4OmJ/Actql/Y3TC9QaCw+qwS6Y/Onh7lM5xenwh5l/1x5d90A6+2GFDQ00u/3xK3IIXH4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Shiju Jose Add scrub control attributes for the DDR5 ECS feature. The Error Check Scrub (ECS) is a feature defined in JEDEC DDR5 SDRAM Specification (JESD79-5) and allows the DRAM to internally read, correct single-bit errors, and write back corrected data bits to the DRAM array while providing transparency to error counts. The ECS control feature allows the request to configure ECS input configurations during system boot or at run-time. The ECS control allows the requester to change the ECS threshold count provided that the request is within the definition specified in DDR5 mode registers, change mode between codeword mode and row count mode, and reset the ECS counter. Signed-off-by: Shiju Jose --- drivers/memory/scrub/memory-scrub.c | 13 ++++++++++++- include/memory/memory-scrub.h | 10 ++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/memory/scrub/memory-scrub.c b/drivers/memory/scrub/memory-scrub.c index c2d794b2624b..43b7da43114f 100755 --- a/drivers/memory/scrub/memory-scrub.c +++ b/drivers/memory/scrub/memory-scrub.c @@ -208,7 +208,8 @@ static bool is_hex_attr(u32 attr) static bool is_string_attr(u32 attr) { - return attr == scrub_speed_available; + return attr == scrub_speed_available || + attr == scrub_threshold_available; } static struct attribute *scrub_genattr(const void *drvdata, @@ -269,6 +270,16 @@ static const char * const scrub_common_attrs[] = { [scrub_enable] = "enable", [scrub_speed] = "speed", [scrub_speed_available] = "speed_available", + /* scrub attributes - DDR5 ECS/common */ + [scrub_ecs_log_entry_type] = "ecs_log_entry_type", + [scrub_ecs_log_entry_type_per_dram] = "ecs_log_entry_type_per_dram", + [scrub_ecs_log_entry_type_per_memory_media] = "ecs_log_entry_type_per_memory_media", + [scrub_mode] = "mode", + [scrub_mode_counts_rows] = "mode_counts_rows", + [scrub_mode_counts_codewords] = "mode_counts_codewords", + [scrub_reset_counter] = "reset_counter", + [scrub_threshold] = "threshold", + [scrub_threshold_available] = "threshold_available", }; static struct attribute ** diff --git a/include/memory/memory-scrub.h b/include/memory/memory-scrub.h index d7cbde4718d0..74ad5addd5b3 100755 --- a/include/memory/memory-scrub.h +++ b/include/memory/memory-scrub.h @@ -23,6 +23,16 @@ enum scrub_attributes { scrub_enable, scrub_speed, scrub_speed_available, + /* scrub attributes - DDR5 ECS/common */ + scrub_ecs_log_entry_type, + scrub_ecs_log_entry_type_per_dram, + scrub_ecs_log_entry_type_per_memory_media, + scrub_mode, + scrub_mode_counts_rows, + scrub_mode_counts_codewords, + scrub_reset_counter, + scrub_threshold, + scrub_threshold_available, max_attrs, }; From patchwork Thu Nov 23 17:43:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13466481 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5715C5AD4C for ; Thu, 23 Nov 2023 17:44:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 027876B0688; Thu, 23 Nov 2023 12:44:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ECB9B6B068A; Thu, 23 Nov 2023 12:44:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD5606B068B; Thu, 23 Nov 2023 12:44:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BE1BF6B0688 for ; Thu, 23 Nov 2023 12:44:16 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 971D91A1448 for ; Thu, 23 Nov 2023 17:44:16 +0000 (UTC) X-FDA: 81489942912.26.B86536F Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf02.hostedemail.com (Postfix) with ESMTP id A277B80023 for ; Thu, 23 Nov 2023 17:44:14 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700761454; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h39DNW7irXEtv45GOKYPqSvCdSod3xDlDMT3ZC3K6EU=; b=ffSEu3AbqurryXoNBCdKE0nW5ZfJgQ2Wr5E9qQSsyGF4B36juFuOHec/mV0DUvc2s9KJmw 4hCWjHLHcsELVulbGVkk2RFaqza+Yrr9BekTXR7zgR8TDDRc5pA8prIMzOhAAjn9ri0++O npnwPD1Kq5jR8SORJDQp3PfSS4mwtZg= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700761454; a=rsa-sha256; cv=none; b=XdsIM3BKh+a2A5VRKzXsweMwJ6Jez2AcOrPeqlHe3RNBsvz4Qgd3P2HOtX2F+Q8UgsG21s 5RPNGw1bSnnE2LSHQdUfBCqU9dDSyIo53f70jsfN9XEZ2q/AxjgNcJoweRmLwIyiZGSKio ivezk7a7LtCGymTsZ+yUfd7z+r/Rk4w= Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Sblk31pMTz6K5pv; Fri, 24 Nov 2023 01:39:55 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 23 Nov 2023 17:44:11 +0000 From: To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 09/11] cxl/memscrub: Register CXL device DDR5 ECS with scrub configure driver Date: Fri, 24 Nov 2023 01:43:52 +0800 Message-ID: <20231123174355.1176-10-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20231123174355.1176-1-shiju.jose@huawei.com> References: <20231123174355.1176-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml100003.china.huawei.com (7.191.160.210) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: A277B80023 X-Stat-Signature: z4ut4zy9spz7my3pdt5zh1tcpfhj5ztx X-Rspam-User: X-HE-Tag: 1700761454-805190 X-HE-Meta: U2FsdGVkX19jlJ/zHFnM8WTGN7M+HIiXGnwGG2G1cgay1yBfF5p3c4VIHJ2lPmMfiVdVvXrggotTU4f1AQM620fer9VUTIz7e2d0qjiejGqC9ClQXyzAtT/dH9uaqD1yMuB2/Og5yof7ILlkCfDLcWtjOajv8lVFHH98dwkqklrxo8W7FVKzl74GoUxp3OaxGK9MMJcfXfvIsNq4whlBIgC/CIBeegI7CGYGaNXndnra8VUbHR33CHYxuf7KFhHF6hmb7Eef26bvtcnWJohNyRL3Qyn1LN+cnGb812GqrUjA4V+7MZogYxPp6W9SBxhp59fMOS6Nr/jgTfeiuVcJzJqaUVH4+G3u+pCRSI5nIUO/HJdQVMT4IClApOOKTZXUEFp+VlaM4xH7qx8fNJqsWY8zvWhxNH+eg4vzcyl9W7NtyOJps6A8ksH3iwueqmMzqquELrMpr6+Sz/1YKAm+vWY5zaz6KXMTBaxqe337VMSQ6EUqX6c4bgCLK6GYR47uJR4vBel2tH9BQghdencE3bTkph28cJmbZsSHlDDkKaIOSQ81lU0Ts/+waa/p/c1TKmvCmi4BdQfzg6HeGCZtBXCG/KMxE3O+Z94Hg1IQBJcGSSBLvbAxsOuiE5Nmzgl6Rf0UALwSWOJ6rpJQE9VGkPqsNUGtJ8NOA8/Zk/Ij9SP/pIP15tVXs9J3C5K8MXhfsf8IGLyhir2De4oMlkEIpHrom7vDO2bG4jBSImAr0lt0wnC66qMYWU1sZkhpNHLxMBSudcdK14dcUzFyKiAgtC8zr7PgyMd6dJ8vt2aoAtH+4nSRqOOtVPvzX4SZYD7sGIyma5sOm3SvsAkKHvdUmfJNcOElNZw/SxMDQmQy7unXRjFd4dfPMCjkJDZKGVlcWm5bJ3OEjofRRXdgd8aacvTCaopwmAVSCacEr49h2w6OCc0BX33LxntYXmXy2VaZsBLP6/uMUO+8PgFYs4v 0bVlo2G6 xFL/tW0cwLdIzpRGpGelnr7PCfc+hAOK0gwTS+RtGg82wM4hLV/1l0q05zAIXYMXdJr+WNSSzI4cFqLuJ+S7U5QHGsWK86aS7zy83BlQy3YFQcDI58BvJOS5wuEuvSDVjpFAfyn5TIAEgGQg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Shiju Jose Register with the scrub configure driver to expose the sysfs attributes to the user for configuring the CXL memory device's ECS feature. Add the callback functions to support configuring the CXL memory device ECS. Signed-off-by: Shiju Jose --- drivers/cxl/core/memscrub.c | 239 +++++++++++++++++++++++++++++++++++- 1 file changed, 236 insertions(+), 3 deletions(-) diff --git a/drivers/cxl/core/memscrub.c b/drivers/cxl/core/memscrub.c index c09f9fa5044a..d4227ecb91d7 100644 --- a/drivers/cxl/core/memscrub.c +++ b/drivers/cxl/core/memscrub.c @@ -460,6 +460,11 @@ EXPORT_SYMBOL_NS_GPL(cxl_mem_patrol_scrub_init, CXL); #define CXL_MEMDEV_ECS_GET_FEAT_VERSION 0x01 #define CXL_MEMDEV_ECS_SET_FEAT_VERSION 0x01 +#define CXL_DDR5_ECS "cxl_ecs" + +/* The default number of regions for CXL memory device ECS */ +#define CXL_MEMDEV_ECS_NUM_REGIONS 1 + static const uuid_t cxl_ecs_uuid = UUID_INIT(0xe5b13f22, 0x2328, 0x4a14, 0xb8, 0xba, 0xb9, 0x69, 0x1e, \ 0x89, 0x33, 0x86); @@ -577,9 +582,8 @@ static int cxl_mem_ecs_get_attrbs(struct device *dev, int fru_id, return 0; } -static int __maybe_unused -cxl_mem_ecs_set_attrbs(struct device *dev, int fru_id, - struct cxl_memdev_ecs_params *params, u8 param_type) +static int cxl_mem_ecs_set_attrbs(struct device *dev, int fru_id, + struct cxl_memdev_ecs_params *params, u8 param_type) { struct cxl_memdev_ecs_feat_read_attrbs *rd_attrbs __free(kvfree) = NULL; struct cxl_memdev_ecs_set_feat_pi *set_pi __free(kvfree) = NULL; @@ -726,10 +730,231 @@ cxl_mem_ecs_set_attrbs(struct device *dev, int fru_id, return 0; } +static int cxl_mem_ecs_log_entry_type_write(struct device *dev, int region_id, long val) +{ + struct cxl_memdev_ecs_params params; + int ret; + + params.log_entry_type = val; + ret = cxl_mem_ecs_set_attrbs(dev, region_id, ¶ms, + CXL_MEMDEV_ECS_PARAM_LOG_ENTRY_TYPE); + if (ret) { + dev_err(dev->parent, "Set CXL ECS params for log entry type fail ret=%d\n", + ret); + return ret; + } + + return 0; +} + +static int cxl_mem_ecs_threshold_write(struct device *dev, int region_id, long val) +{ + struct cxl_memdev_ecs_params params; + int ret; + + params.threshold = val; + ret = cxl_mem_ecs_set_attrbs(dev, region_id, ¶ms, + CXL_MEMDEV_ECS_PARAM_THRESHOLD); + if (ret) { + dev_err(dev->parent, "Set CXL ECS params for threshold fail ret=%d\n", + ret); + return ret; + } + + return 0; +} + +static int cxl_mem_ecs_mode_write(struct device *dev, int region_id, long val) +{ + struct cxl_memdev_ecs_params params; + int ret; + + params.mode = val; + ret = cxl_mem_ecs_set_attrbs(dev, region_id, ¶ms, + CXL_MEMDEV_ECS_PARAM_MODE); + if (ret) { + dev_err(dev->parent, "Set CXL ECS params for mode fail ret=%d\n", + ret); + return ret; + } + + return 0; +} + +static int cxl_mem_ecs_reset_counter_write(struct device *dev, int region_id, long val) +{ + struct cxl_memdev_ecs_params params; + int ret; + + params.reset_counter = val; + ret = cxl_mem_ecs_set_attrbs(dev, region_id, ¶ms, + CXL_MEMDEV_ECS_PARAM_RESET_COUNTER); + if (ret) { + dev_err(dev->parent, "Set CXL ECS params for reset ECC counter fail ret=%d\n", + ret); + return ret; + } + + return 0; +} + +/** + * cxl_mem_ecs_is_visible() - Callback to return attribute visibility + * @drv_data: Pointer to driver-private data structure passed + * as argument to devm_scrub_device_register(). + * @attr: Scrub attribute + * @region_id: ID of the memory region + * + * Returns: 0 on success, an error otherwise + */ +static umode_t cxl_mem_ecs_is_visible(const void *drv_data, u32 attr, int region_id) +{ + switch (attr) { + case scrub_reset_counter: + return 0200; + case scrub_ecs_log_entry_type_per_dram: + case scrub_ecs_log_entry_type_per_memory_media: + case scrub_mode_counts_rows: + case scrub_mode_counts_codewords: + case scrub_threshold_available: + return 0444; + case scrub_ecs_log_entry_type: + case scrub_mode: + case scrub_threshold: + return 0644; + default: + return 0; + } +} + +/** + * cxl_mem_ecs_read() - Read callback for data attributes + * @dev: Pointer to scrub device + * @attr: Scrub attribute + * @region_id: ID of the memory region + * @val: Pointer to the returned data + * + * Returns: 0 on success, an error otherwise + */ +static int cxl_mem_ecs_read(struct device *dev, u32 attr, int region_id, u64 *val) +{ + struct cxl_memdev_ecs_params params; + int ret; + + if (attr == scrub_ecs_log_entry_type || + attr == scrub_ecs_log_entry_type_per_dram || + attr == scrub_ecs_log_entry_type_per_memory_media || + attr == scrub_mode || + attr == scrub_mode_counts_rows || + attr == scrub_mode_counts_codewords || + attr == scrub_threshold) { + ret = cxl_mem_ecs_get_attrbs(dev, region_id, ¶ms); + if (ret) { + dev_err(dev->parent, "Get CXL ECS params fail ret=%d\n", ret); + return ret; + } + } + + switch (attr) { + case scrub_ecs_log_entry_type: + *val = params.log_entry_type; + break; + case scrub_ecs_log_entry_type_per_dram: + if (params.log_entry_type == ECS_LOG_ENTRY_TYPE_DRAM) + *val = 1; + else + *val = 0; + break; + case scrub_ecs_log_entry_type_per_memory_media: + if (params.log_entry_type == ECS_LOG_ENTRY_TYPE_MEM_MEDIA_FRU) + *val = 1; + else + *val = 0; + break; + case scrub_mode: + *val = params.mode; + break; + case scrub_mode_counts_rows: + if (params.mode == ECS_MODE_COUNTS_ROWS) + *val = 1; + else + *val = 0; + break; + case scrub_mode_counts_codewords: + if (params.mode == ECS_MODE_COUNTS_CODEWORDS) + *val = 1; + else + *val = 0; + break; + case scrub_threshold: + *val = params.threshold; + break; + default: + return -ENOTSUPP; + } + + return 0; +} + +/** + * cxl_mem_ecs_write() - Write callback for data attributes + * @dev: Pointer to scrub device + * @attr: Scrub attribute + * @region_id: ID of the memory region + * @val: Value to write + * + * Returns: 0 on success, an error otherwise + */ +static int cxl_mem_ecs_write(struct device *dev, u32 attr, int region_id, u64 val) +{ + switch (attr) { + case scrub_ecs_log_entry_type: + return cxl_mem_ecs_log_entry_type_write(dev, region_id, val); + case scrub_mode: + return cxl_mem_ecs_mode_write(dev, region_id, val); + case scrub_reset_counter: + return cxl_mem_ecs_reset_counter_write(dev, region_id, val); + case scrub_threshold: + return cxl_mem_ecs_threshold_write(dev, region_id, val); + default: + return -ENOTSUPP; + } +} + +/** + * cxl_mem_ecs_read_strings() - Read callback for DDR5 ECS string attributes + * @dev: Pointer to ECS scrub device + * @attr: ECS scrub attribute + * @region_id: ID of the memory media FRU. + * @buf: Pointer to the buffer for copying returned string + * + * Returns: 0 on success, an error otherwise + */ +static int cxl_mem_ecs_read_strings(struct device *dev, u32 attr, + int region_id, char *buf) +{ + + switch (attr) { + case scrub_threshold_available: + return sysfs_emit(buf, "256,1024,4096\n"); + default: + return -ENOTSUPP; + } +} + +static const struct scrub_ops cxl_ecs_ops = { + .is_visible = cxl_mem_ecs_is_visible, + .read = cxl_mem_ecs_read, + .write = cxl_mem_ecs_write, + .read_string = cxl_mem_ecs_read_strings, +}; + int cxl_mem_ddr5_ecs_init(struct cxl_memdev *cxlmd) { + char scrub_name[CXL_MEMDEV_MAX_NAME_LENGTH]; struct cxl_mbox_supp_feat_entry feat_entry; struct cxl_ecs_context *cxl_ecs_ctx; + struct device *cxl_scrub_dev; int nmedia_frus; int ret; @@ -749,6 +974,14 @@ int cxl_mem_ddr5_ecs_init(struct cxl_memdev *cxlmd) cxl_ecs_ctx->nregions = nmedia_frus; cxl_ecs_ctx->get_feat_size = feat_entry.get_feat_size; cxl_ecs_ctx->set_feat_size = feat_entry.set_feat_size; + + snprintf(scrub_name, sizeof(scrub_name), "%s_%s", + CXL_DDR5_ECS, dev_name(&cxlmd->dev)); + cxl_scrub_dev = devm_scrub_device_register(&cxlmd->dev, scrub_name, + cxl_ecs_ctx, &cxl_ecs_ops, + cxl_ecs_ctx->nregions); + if (IS_ERR(cxl_scrub_dev)) + return PTR_ERR(cxl_scrub_dev); } return 0; From patchwork Thu Nov 23 17:43:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13466482 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8FDE0C636CB for ; Thu, 23 Nov 2023 17:44:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 816116B068A; Thu, 23 Nov 2023 12:44:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7EF356B068B; Thu, 23 Nov 2023 12:44:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 666D46B068C; Thu, 23 Nov 2023 12:44:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 530196B068A for ; Thu, 23 Nov 2023 12:44:17 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3878E1210A1 for ; Thu, 23 Nov 2023 17:44:17 +0000 (UTC) X-FDA: 81489942954.22.7DD57BE Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf04.hostedemail.com (Postfix) with ESMTP id 2F27940014 for ; Thu, 23 Nov 2023 17:44:14 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700761455; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JKUF9IcADAMJQiVs2ROSM7VATeZNKbIi5ZRlD7UBNYM=; b=gC9Z/elCLZK8FOg/A5n3FZfXbtF7Q4NQ9bYFroDIPgGMnKh2jZknwgcBIVocZYElFKRz2p a6bp0w7lOM3cgJllAY6Pv8wP8An8qIdB6s1eWhQbTQvWnFJ3uxcUdkyoK8iyb8a5I1/AwA pJldyvYioRvq3RJCQ8nzG7uP9x9pBiM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700761455; a=rsa-sha256; cv=none; b=v38MFiJdhFbtFCe97M61HiAfKWCxx02XnO1AWM9vfXKBQ8UfzaMHFeAVndoQsgfjWObywr ZBNm9mxPGgVMutpu2EQwbPDRYNdn6jCcU5sN+72P8aFje3tIfbl7I4ONC/c3NtRqYDQKo1 rvAYShRMiAJs1iqlShYWMcWCpO/5Xhg= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Sblk363Ddz6K5qw; Fri, 24 Nov 2023 01:39:55 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 23 Nov 2023 17:44:12 +0000 From: To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 10/11] memory: scrub: sysfs: Add Documentation for set of common scrub attributes Date: Fri, 24 Nov 2023 01:43:53 +0800 Message-ID: <20231123174355.1176-11-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20231123174355.1176-1-shiju.jose@huawei.com> References: <20231123174355.1176-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml100003.china.huawei.com (7.191.160.210) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 2F27940014 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 8pfhgquj5zxfdcxfh4647gcj4xsw567c X-HE-Tag: 1700761454-798160 X-HE-Meta: U2FsdGVkX181UGopODwskIEaTXyNlz7bWI3KqMv0KgPQjpWyOCZpZlRiQgFO/MgDGfde8VAi3vmotW1/48yzBlcAwC00Tbt/078ox/vCUbWXYtyOZI3Q661OHFSg541z69fckYtdMC4jatmzUhVGr0cokcBWR55hsZ96bNcXeajyQSo1Gj7cdBRgr83f08iVav1vntaoYKjE1q/RBYl4pS0ZCNli9hJouRwNKXkK6rgtoHEAG3+zmUhcFVjRW6B0jKpXivBGhoxgPx+VakyESUuxDiqvZyOsBHs7hT44dpUiuDPEAizuJTvo8F6Yk9B385dywBLP587fPwSmHH7yg7f9BFcFoYtVklTmiPLTayVFDGv/lZyyBRTY1ZPyQQ11ouSZ75Qlbzi2gonZoYuKxBPbaKkrEZCizbV5s++rLaHXwiSv0JEdiIK5t1RVwSXViJkmrfoHU158h/EH4m9tjQhbpmh3S+WCgZJ3R4yJLaKSOWk5oCNF347rin6eUBYc8zIOSL0s1/q8KWQtJjsoPJ/CG5k0fzcVeY99eD+/QRF+0A15ZL5r7M6+tmSjGtyy437lr32GRXgXqyCjhYLXKVhO3L+THa3Qt0qVyw6fbca6HxpqSZP59/HJSbrdeyOV+8gt6sEeVThaHg7x3ypb5rC0HCm0CUAuWv6U44CoptyMA9nmqSvbBatX+Mk8Hp9FYRC8NnAWKrLeruHqNcfze4iqnHhpId4pUfnqVcwamDsRHXva0Lm2hlDJkrML34viRyLr/0cgpnjS6urxXPsnl0a8IkCsA7zoSd9aUSqkvWYo2rVFjGB/2emRG3RjL+vxVAPytq7AdagnqnzPD6afUwi5icdcGMwoouOMNLcYShw2Ue1Oifbx9yFgxnxLlaphQf22ogQ6dDQ0rJti3zGOG/iNN/jrYXUfqTmrKea4nC5Tg4JsoIB1TNE6qhtfN8jCXNaEfcYvLJHm1GZ3yng qvlACAN0 ezfOSXgMs23FZ9ZveQAb/6xOLh+B0wknpnbOCtXMq+CykaaMBh7D/2nZCtI23SMbPzQ50w8NcTXiRP9gNfO7xsNGXc1EIptkrrRFayEsAf1RKHXv0/5ZqHmSuk6ravnUK9eFQjwYB41PjEe3czSMZBm+0yUCbaSmKfyn3mTV3wa2c81WFnVov79ukJywuQN/GzeNMq2Ea+4g5ekGTpM9l5YILf4xLE55B5djL X-Bogosity: Ham, tests=bogofilter, spamicity=0.000018, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Shiju Jose Add sysfs documentation for the set of common scrub attributes those are exposed in /sys/class/scrub/ by the scrub configure driver and support user to configuring attributes of a scrub device. Signed-off-by: Shiju Jose --- .../ABI/testing/sysfs-class-scrub-configure | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-scrub-configure diff --git a/Documentation/ABI/testing/sysfs-class-scrub-configure b/Documentation/ABI/testing/sysfs-class-scrub-configure new file mode 100644 index 000000000000..5e965b3ad088 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-class-scrub-configure @@ -0,0 +1,82 @@ +What: /sys/class/scrub/ +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + The scrub/ class subdirectory belongs to the + scrubber subsystem. + +What: /sys/class/scrub/scrubX/ +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + The /sys/class/scrub/scrub{0,1,2,3,...} directories + correspond to each scrub device. + +What: /sys/class/scrub/scrubX/name +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + (RO) name of the memory scrub device + +What: /sys/class/scrub/scrubX/regionY/ +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + The /sys/class/scrub/scrubX/region{0,1,2,3,...} + directories correspond to each scrub region under a scrub device. + Scrub region is a physical address range for which scrub may be + separately controlled. Regions may overlap in which case the + scrubbing rate of the overlapped memory will be at least that + expected due to each overlapping region. + +What: /sys/class/scrub/scrubX/regionY/addr_base +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + (RW) The base of the address range of the memory region + to be scrubbed. + On reading, returns the base of the memory region for + the actual address range(The platform calculates + the nearest patrol scrub boundary address from where + it can start scrub). + +What: /sys/class/scrub/scrubX/regionY/addr_size +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + (RW) The size of the address range to be scrubbed. + On reading, returns the size of the memory region for + the actual address range. + +What: /sys/class/scrub/scrubX/regionY/enable +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + (WO) Start/Stop scrub the memory region. + 1 - enable the memory scrub. + 0 - disable the memory scrub.. + +What: /sys/class/scrub/scrubX/regionY/speed_available +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + (RO) Supported range for the scrub speed(scrub rate) + by the scrubber for a memory region. + The unit of the scrub rate vary depends on the scrub. + +What: /sys/class/scrub/scrubX/regionY/speed +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + (RW) The scrub speed(scrub rate) on the memory region specified + and it must be with in the supported range by the scrub. + The unit of the scrub rate vary depends on the scrub. From patchwork Thu Nov 23 17:43:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13466483 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 469B4C5AD4C for ; Thu, 23 Nov 2023 17:44:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 111736B068C; Thu, 23 Nov 2023 12:44:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0730D6B068D; Thu, 23 Nov 2023 12:44:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DBAD96B068E; Thu, 23 Nov 2023 12:44:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CD5C16B068C for ; Thu, 23 Nov 2023 12:44:18 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9ECB6404AB for ; Thu, 23 Nov 2023 17:44:18 +0000 (UTC) X-FDA: 81489942996.11.3F7E838 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf15.hostedemail.com (Postfix) with ESMTP id 92F25A0002 for ; Thu, 23 Nov 2023 17:44:16 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700761456; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IiMsgVXrPEXlCjzvkurdHwvgrdFzuqrpBmly0YBvSSQ=; b=vKSTIGSufxo6S31DVKX0JmFVsUuCK5dIJuemzs003g1FbpTP+5Z4hdqYL8EekTcw/RXNJE C7w1E3rRxQApa1z61WGI2oTYa5sD/7fVBVCN/+hLSZ5bKzkRFjti5EBhPtYEgTwp5ee+pY pdvQNTooObXx5ncXTgMhsrbpX6cd/l0= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf15.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700761456; a=rsa-sha256; cv=none; b=E8wdm37g3wgKMfIeC4wOC2oTTd63IhGs8Da/MEAK5TWmjTCJGKsQwcKuq0epshyPRgxv1X l1YiIn9rS2RUsBA3Yso3+BwfIdsJAgWhFYM2I250noj0uLaOpCNrcXhORiCtljbckMgBOg PFf/p88lOp0bDxDZDIIHvUMJKA66kj8= Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Sblk51lXTz6K5sT; Fri, 24 Nov 2023 01:39:57 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 23 Nov 2023 17:44:13 +0000 From: To: , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 11/11] cxl: scrub: sysfs: Add Documentation for CXL memory device scrub control attributes Date: Fri, 24 Nov 2023 01:43:54 +0800 Message-ID: <20231123174355.1176-12-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20231123174355.1176-1-shiju.jose@huawei.com> References: <20231123174355.1176-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml100003.china.huawei.com (7.191.160.210) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 92F25A0002 X-Stat-Signature: 6gzoe5rdqbsnh64zty8gfc6msohrhpze X-Rspam-User: X-HE-Tag: 1700761456-222309 X-HE-Meta: U2FsdGVkX1/SpQnF8TsalV9rP3YmoSybCSWZ100yLY+L8310UDMN/bnhsxGJ4h3W3316dVtR9bbZUBtdg1E+slKLCZ6pF4fvk2aFqq7x4GKlbyZdtpvVGjYtE0KkVt70MhH3PwaqUaz0uSGNQ66FgFE/K3+IM8ak5R3O/ToVkJor/XciSf+NlF0r9iHXtZ1RiRFG9SHj947obNxv1Ol0m3AbqdIxWQK0mAvskty3fNeFQbPKoJ3o7fndjDJQDVWVFJNAfSGrMXo2Nhk2aW7ve77SfoGW3690Tg08cORNhsnMnQfKxQTAZmB00sFPrv/WLySBa2lloLZHisGmv6a29d3rjY5gzUJyPd8lzCdkresbTGMdNd/XmpRnoEh6eIKKJ9q3WegkmlGHRpcUZSfclnCETHFoCn2w5USOr6u1GL5QCdvGg4bl9No7f/u5pBOAisQzPYJPf57zsUinY5YiWOobewJcz4+zSRiUPX72MNFikBYpEFyCLkXecxnYHybl+aIzXsdbZq0If3X+IBHHgQljh7/Em6J/XEeMJEx+rjXusXv7+bR14TjQz+sURdttqEQNM1qVEDqhLYM3r1jxX0np09dBo4b6HHTpwHeuxlmFvDaf5a1xc1ZJjAHD7TKCach1LJgNQt4F3zLMx8fUJGqHTOyd1G2wtsCTSt08URMjI7GmAaJ7xdZkcVd82ImvwxBXkQyIXm/L8sNyB6NPM7bU7T6jDqSd+xfbEYpaxJQzncc+GT0gBDUcNNiU9ksmkD9DfIt4N9UdkKg7YXVk7QwnLboMXDAIMX59zaRvOwHzQjYEuuOmGwipQkv7SP8y4Lrv29O644AH69BIrtVhSkykbB0EMGdoB8NCC/3bnsYy9iuk8kfZo3IvQDj9e0YlxVvFDEkmK1MwtEOxqM3zHRiHWc95mMHN5woQeFHOqs/tIWyf1TBP65c21j/ij1OGgExiDuDHXdZLrywdgX3 KlT9CJoM wrXiq6zZhDfKNBVDrw4TjyKkOKiDlZzfrVda3XLyb9EBpMDzeo8ch2gHlDB0TUETqfUJOwglabNr+e7wP6ptFL+GASUTeuyCQPMaPVucB5ALXk6pNIHDWtw6GN5ezG6DPxjHpk7/afeavmaKloWPaCszV8p9bWMVDAH3Znkyda0B/QS/hnvHpvb8b4NsGP06JwglQVMIzT8573WFfxWZderfJZq0woBfMh+17 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Shiju Jose Add sysfs documentation for the CXL memory device scrub control attributes those are exposed in /sys/class/scrub/ by the scrub driver. These attributes support user configuring a CXL memory device scrub. Signed-off-by: Shiju Jose --- .../testing/sysfs-class-cxl-scrub-configure | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-cxl-scrub-configure diff --git a/Documentation/ABI/testing/sysfs-class-cxl-scrub-configure b/Documentation/ABI/testing/sysfs-class-cxl-scrub-configure new file mode 100644 index 000000000000..57ba63d5390f --- /dev/null +++ b/Documentation/ABI/testing/sysfs-class-cxl-scrub-configure @@ -0,0 +1,135 @@ +What: /sys/class/scrub/ +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + The scrub/ class subdirectory belongs to the scrub + subsystem. + +What: /sys/class/scrub/scrubX/ +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + The /sys/class/scrub/scrub{0,1,2,3,...} directories + correspond to each scrub device. + +What: /sys/class/scrub/scrubX/name +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + (RO) name of the memory scrub device + +What: /sys/class/scrub/scrubX/regionY/ +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + The /sys/class/scrub/scrubX/region{0,1,2,3,...} + directories correspond to each scrub region under a scrub device. + Scrub region is a physical address range or for example + memory media FRU of DDR5 ECS feature for which scrub may be + separately controlled. + +What: /sys/class/scrub/scrubX/regionY/enable +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + (WO) Start/Stop CXL memory patrol scrub. + 1 - enable the CXL memory patrol scrub. + 0 - disable the CXL memory patrol scrub. + +What: /sys/class/scrub/scrubX/regionY/speed +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + (RW) The scrub cycle to set for the CXL memory + patrol scrub and it must be within the supported + range. The unit of the scrub cycle is hour. + +What: /sys/class/scrub/scrubX/regionY/speed_available +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + (RO) Supported range of the scrub cycle by the + CXL memory patrol scrub. + The unit of the scrub cycle is hour. + +What: /sys/class/scrub/scrubX/regionY/ecs_log_entry_type +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + (RW) The log entry type of how the DDR5 ECS log is + reported. + 00b - per DRAM. + 01b - per memory media FRU. + +What: /sys/class/scrub/scrubX/regionY/ecs_log_entry_type_per_dram +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + (RO) Returns true if current log entry type of DDR5 ECS + region is per DRAM. + +What: /sys/class/scrub/scrubX/regionY/ecs_log_entry_type_per_memory_media +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + (RO) Returns true if current log entry type of DDR5 ECS + region is per memory media FRU. + +What: /sys/class/scrub/scrubX/regionY/mode +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + (RW) The mode of how the DDR5 ECS counts the errors. + 0 - ECS counts rows with errors. + 1 - ECS counts codewords with errors. + +What: /sys/class/scrub/scrubX/regionY/mode_counts_rows +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + (RO) Returns true if current mode of DDR5 ECS region + is counts rows with errors. + +What: /sys/class/scrub/scrubX/regionY/mode_counts_codewords +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + (RO) Returns true if current mode of DDR5 ECS region + is counts codewords with errors. + +What: /sys/class/scrub/scrubX/regionY/reset_counter +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + (WO) DDR5 ECS reset ECC counter. + 0 - normal, ECC counter running actively. + 1 - reset ECC counter to the default value. + +What: /sys/class/scrub/scrubX/regionY/threshold +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + (RW) DDR5 ECS threshold count per GB of memory cells. + +What: /sys/class/scrub/scrubX/regionY/threshold_available +Date: November 2023 +KernelVersion: 6.8 +Contact: linux-kernel@vger.kernel.org +Description: + (RO) Supported list of DDR5 ECS threshold count per GB of + memory cells.