From patchwork Tue Jul 16 15:03:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13734599 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 F0941C3DA5E for ; Tue, 16 Jul 2024 15:05:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 857056B009F; Tue, 16 Jul 2024 11:04:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BA276B00A0; Tue, 16 Jul 2024 11:04:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 60C9D6B00A1; Tue, 16 Jul 2024 11:04:52 -0400 (EDT) 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 42CA56B009F for ; Tue, 16 Jul 2024 11:04:52 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EF964C0114 for ; Tue, 16 Jul 2024 15:04:51 +0000 (UTC) X-FDA: 82345937982.26.465DEFF Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf13.hostedemail.com (Postfix) with ESMTP id 8A8A1200BC for ; Tue, 16 Jul 2024 15:04:30 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; spf=pass (imf13.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=1721142251; 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=3MRgZvJzZd2CJScm8W5UhSC/Uev1hk1qtLMbOX6bkvo=; b=qIE3qQ83/x5vxVGaXHQ5GUd6etzLzxORIZDKLTKUMv4nlsZfsv4MqvlFNukqOaoZ6qCk4w y2Fo/RMY3IeCMKDpFVQ/M2v+Q98Vs7LcFWfIX97iMWzhP4dXqtUoX+yBCzxhmkQpgT0drC Dg75MRN1nHsKK8lIyxO1Tc6OPTEouiQ= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; spf=pass (imf13.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=1721142251; a=rsa-sha256; cv=none; b=L96+B5YCyJlAmgFX8qvx/roOf06MfAeloxWFmC/sTxijFmrHNui2M04B3SBNZHVPKkcHdH da9OBGab2F1T95gRd9tTaoqWkLonFa4M4+HV5zbE59d02NG0Tnd1h3ed3n59eh1Lso9G1g F+55XDDsTMUoNrYvM/Toj/+mGNzSIDc= Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4WNj3h3dCwz6H6pv; Tue, 16 Jul 2024 23:02:40 +0800 (CST) Received: from lhrpeml500006.china.huawei.com (unknown [7.191.161.198]) by mail.maildlp.com (Postfix) with ESMTPS id 61717140B38; Tue, 16 Jul 2024 23:04:25 +0800 (CST) Received: from P_UKIT01-A7bmah.china.huawei.com (10.48.159.153) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 16 Jul 2024 16:04:23 +0100 From: To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH v9 01/11] EDAC: Add generic EDAC RAS feature driver Date: Tue, 16 Jul 2024 16:03:25 +0100 Message-ID: <20240716150336.2042-2-shiju.jose@huawei.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20240716150336.2042-1-shiju.jose@huawei.com> References: <20240716150336.2042-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.48.159.153] X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) To lhrpeml500006.china.huawei.com (7.191.161.198) X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 8A8A1200BC X-Stat-Signature: r4noxnfnzodhutweqm7crnjdjww6o4em X-Rspam-User: X-HE-Tag: 1721142269-920422 X-HE-Meta: U2FsdGVkX19ytOCPKRwEdbPZBgv5qlEfWAWSbMbYZXxIY71oe3ubk/uNQQHeLeCv0GzSpw1QOSMBc4EsdQWpUOoTw5IhdcK5IerkxBZ4UbVqRJSYl/yJBmqvaEpLWxL1sIVRi5WFaqXGAeqsSHA56CEQaHMjkMgFWcvoznzCjUEN/iqMIuYXML3DkP+R+lWgPZgnzD/QExIE5s2j8KzXr/Pqt0YH0jUhjj8wxCAbr+cMt3uWwWhTJcTDLQ0GfJmPiVK/zwc6b8zTo/mRY/YRxx+EYap0rx2INjChWU19zi8B+1m7iQyt1bfqI1lZfnjeodsFzT0mq7wyDw71o2AEX1q5iUNQcOoOo54GlMvzelrDRoXhlUHPIkQEHlk3YH3zpOlHzHltEIf+8NDaCFxPlDDsdDG0roe9lNHFhqS133HCNYVWS9bLT1NTJMsI665yf3/dAEXoAsmoAhE0AVkQYhXmv+q9OuUICAX3nwOv0PD8E6KKHSUtvmm5w72ctaQ1qj28bO6XbBvxMObOvMR2Ed2X2g5yC1Rjc9tmPSCq5uyp9B4A0UeegCLGMXDjwOagAqjIu/R6S288ftKQKoYl2dhG+treY5X/vF+t+e3AjQAjYcbom4ZrrypI0me3lCyDwjJ4BLyuqdbgiZ3VZk/zF1UVL15t3TEGFAFb/dAkEhe65fmHxmugkg52JCqm6s3kyhSAhiSiZ2ZQjVlPs+Bb2hbg0Uotxg4w5KJtgqrayv5A9NuCvZg6p1ArY3LA69tHMN2BPbwjlSdj2crlnD719ZWXnDb+3NCG6/VHvq2NaKCAqYHoZCvArwMsmcZGy8vmyakFIcGFAtQjo1epOKXpkQsmbedm05RN/8urSJ1mDre/xcHo1ONR54bynfiFvpB9KyEJf3/ue9uUr3/qRqvBAE66FO/hnbqbOAfMiPMzVwxdJrziHDP0+Tcls0Pc0jpl8W3YxhjFChI4ZChwmXq r6qDKvO0 5sSSsa4zcJ1WLIccfowOorBTY5EFIdlMMOU9VR5obis0QzpDu7IzJpf/oGuAsbIf65SKLH5pcDY55Vxw3UL/GP0O0LwKfJLhcFijLmwfefVmxNYcj6T8dRG9zzKruQyLR3DyiCfesISf3/+jXTi+tG/n+EpJ2CP5FmCpGHOh0MDu/iel2avULQPr6vPUVIBY3dnmu9zjsgQrCMaHlg+kO4VcSjg== 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 generic EDAC driver supports registering RAS features supported in the system. The driver exposes feature's control attributes to the userspace in /sys/bus/edac/devices/// Co-developed-by: Jonathan Cameron Signed-off-by: Jonathan Cameron Signed-off-by: Shiju Jose --- drivers/edac/Makefile | 1 + drivers/edac/edac_ras_feature.c | 155 +++++++++++++++++++++++++++++++ include/linux/edac_ras_feature.h | 66 +++++++++++++ 3 files changed, 222 insertions(+) create mode 100755 drivers/edac/edac_ras_feature.c create mode 100755 include/linux/edac_ras_feature.h diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile index 9c09893695b7..c532b57a6d8a 100644 --- a/drivers/edac/Makefile +++ b/drivers/edac/Makefile @@ -10,6 +10,7 @@ obj-$(CONFIG_EDAC) := edac_core.o edac_core-y := edac_mc.o edac_device.o edac_mc_sysfs.o edac_core-y += edac_module.o edac_device_sysfs.o wq.o +edac_core-y += edac_ras_feature.o edac_core-$(CONFIG_EDAC_DEBUG) += debugfs.o diff --git a/drivers/edac/edac_ras_feature.c b/drivers/edac/edac_ras_feature.c new file mode 100755 index 000000000000..24a729fea66f --- /dev/null +++ b/drivers/edac/edac_ras_feature.c @@ -0,0 +1,155 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * EDAC RAS control feature driver supports registering RAS + * features with the EDAC and exposes the feature's control + * attributes to the userspace in sysfs. + * + * Copyright (c) 2024 HiSilicon Limited. + */ + +#define pr_fmt(fmt) "EDAC RAS CONTROL FEAT: " fmt + +#include + +static void edac_ras_dev_release(struct device *dev) +{ + struct edac_ras_feat_ctx *ctx = + container_of(dev, struct edac_ras_feat_ctx, dev); + + kfree(ctx); +} + +const struct device_type edac_ras_dev_type = { + .name = "edac_ras_dev", + .release = edac_ras_dev_release, +}; + +static void edac_ras_dev_unreg(void *data) +{ + device_unregister(data); +} + +static int edac_ras_feat_scrub_init(struct device *parent, + struct edac_scrub_data *sdata, + const struct edac_ras_feature *sfeat, + const struct attribute_group **attr_groups) +{ + sdata->ops = sfeat->scrub_ops; + sdata->private = sfeat->scrub_ctx; + + return 1; +} + +static int edac_ras_feat_ecs_init(struct device *parent, + struct edac_ecs_data *edata, + const struct edac_ras_feature *efeat, + const struct attribute_group **attr_groups) +{ + int num = efeat->ecs_info.num_media_frus; + + edata->ops = efeat->ecs_ops; + edata->private = efeat->ecs_ctx; + + return num; +} + +/** + * edac_ras_dev_register - register device for ras features with edac + * @parent: client device. + * @name: client device's name. + * @private: parent driver's data to store in the context if any. + * @num_features: number of ras features to register. + * @ras_features: list of ras features to register. + * + * Returns 0 on success, error otherwise. + * The new edac_ras_feat_ctx would be freed automatically. + */ +int edac_ras_dev_register(struct device *parent, char *name, + void *private, int num_features, + const struct edac_ras_feature *ras_features) +{ + const struct attribute_group **ras_attr_groups; + struct edac_ras_feat_ctx *ctx; + int attr_gcnt = 0; + int ret, feat; + + if (!parent || !name || !num_features || !ras_features) + return -EINVAL; + + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + ctx->dev.parent = parent; + ctx->private = private; + + /* Double parse so we can make space for attributes */ + for (feat = 0; feat < num_features; feat++) { + switch (ras_features[feat].feat) { + case ras_feat_scrub: + attr_gcnt++; + break; + case ras_feat_ecs: + attr_gcnt += ras_features[feat].ecs_info.num_media_frus; + break; + default: + ret = -EINVAL; + goto ctx_free; + } + } + + ras_attr_groups = devm_kzalloc(parent, + (attr_gcnt + 1) * sizeof(*ras_attr_groups), + GFP_KERNEL); + if (!ras_attr_groups) { + ret = -ENOMEM; + goto ctx_free; + } + + attr_gcnt = 0; + for (feat = 0; feat < num_features; feat++, ras_features++) { + if (ras_features->feat == ras_feat_scrub) { + if (!ras_features->scrub_ops) + continue; + ret = edac_ras_feat_scrub_init(parent, &ctx->scrub, + ras_features, &ras_attr_groups[attr_gcnt]); + if (ret < 0) + goto ctx_free; + + attr_gcnt += ret; + } else if (ras_features->feat == ras_feat_ecs) { + if (!ras_features->ecs_ops) + continue; + ret = edac_ras_feat_ecs_init(parent, &ctx->ecs, + ras_features, &ras_attr_groups[attr_gcnt]); + if (ret < 0) + goto ctx_free; + + attr_gcnt += ret; + } else { + ret = -EINVAL; + goto ctx_free; + } + } + ras_attr_groups[attr_gcnt] = NULL; + ctx->dev.bus = edac_get_sysfs_subsys(); + ctx->dev.type = &edac_ras_dev_type; + ctx->dev.groups = ras_attr_groups; + dev_set_drvdata(&ctx->dev, ctx); + ret = dev_set_name(&ctx->dev, name); + if (ret) + goto ctx_free; + + ret = device_register(&ctx->dev); + if (ret) { + put_device(&ctx->dev); + return ret; + } + + return devm_add_action_or_reset(parent, edac_ras_dev_unreg, &ctx->dev); + +ctx_free: + kfree(ctx); + return ret; +} +EXPORT_SYMBOL_GPL(edac_ras_dev_register); diff --git a/include/linux/edac_ras_feature.h b/include/linux/edac_ras_feature.h new file mode 100755 index 000000000000..000e99141023 --- /dev/null +++ b/include/linux/edac_ras_feature.h @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * EDAC RAS control features. + * + * Copyright (c) 2024 HiSilicon Limited. + */ + +#ifndef __EDAC_RAS_FEAT_H +#define __EDAC_RAS_FEAT_H + +#include +#include + +#define EDAC_RAS_NAME_LEN 128 + +enum edac_ras_feat { + ras_feat_scrub, + ras_feat_ecs, + ras_feat_max +}; + +struct edac_ecs_ex_info { + u16 num_media_frus; +}; + +/* + * EDAC RAS feature information structure + */ +struct edac_scrub_data { + const struct edac_scrub_ops *ops; + void *private; +}; + +struct edac_ecs_data { + const struct edac_ecs_ops *ops; + void *private; +}; + +struct device; + +struct edac_ras_feat_ctx { + struct device dev; + void *private; + struct edac_scrub_data scrub; + struct edac_ecs_data ecs; +}; + +struct edac_ras_feature { + enum edac_ras_feat feat; + union { + const struct edac_scrub_ops *scrub_ops; + const struct edac_ecs_ops *ecs_ops; + }; + union { + struct edac_ecs_ex_info ecs_info; + }; + union { + void *scrub_ctx; + void *ecs_ctx; + }; +}; + +int edac_ras_dev_register(struct device *parent, char *dev_name, + void *parent_pvt_data, int num_features, + const struct edac_ras_feature *ras_features); +#endif /* __EDAC_RAS_FEAT_H */ From patchwork Tue Jul 16 15:03:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13734590 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 C2F65C3DA59 for ; Tue, 16 Jul 2024 15:04:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A11C6B0082; Tue, 16 Jul 2024 11:04:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 152426B0088; Tue, 16 Jul 2024 11:04:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBDF26B008A; Tue, 16 Jul 2024 11:04:33 -0400 (EDT) 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 C283B6B0088 for ; Tue, 16 Jul 2024 11:04:33 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4A173817AA for ; Tue, 16 Jul 2024 15:04:33 +0000 (UTC) X-FDA: 82345937226.05.A854527 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf21.hostedemail.com (Postfix) with ESMTP id 25F0D1C0020 for ; Tue, 16 Jul 2024 15:04:30 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; spf=pass (imf21.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=1721142252; 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=MawF3QXYY+z0fdhXnN2UiVEGSuV4Ei+HbSmoDlqJP1k=; b=LRkcNiqc0F+vdEl4TaCwSwwhIcFkUL5DrIkq4Rh8nyZ+zpf7zpDAyeiGkegwpAa6FK2482 jz7Fj3tYb/7N87/G7rER7gl127mQlbhTIEGUpFQBCQJmKsrd/Chv3PLBiJbtsFquvlMYKX 7Ee/qIPXwxrJwIOYmhGf3+snIYAKYIY= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; spf=pass (imf21.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=1721142252; a=rsa-sha256; cv=none; b=3SBpLwdBnjtz800G6L7gvmmohpR0Z4JUNaViaF/Q872YaqGj0LsU5EAi5VGtHgE2TEj8pA lNJrGmuzOgtTzpdCYdGW8MIsaZrcv6J+rwLJ9R44UOZoJjXJK+yrJr3UIXuAys0C5Q/Qjw igmpAuk72KGSI8y7kw5nfzY9HOzJmaM= Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4WNj4H5PQ5z6JB50; Tue, 16 Jul 2024 23:03:11 +0800 (CST) Received: from lhrpeml500006.china.huawei.com (unknown [7.191.161.198]) by mail.maildlp.com (Postfix) with ESMTPS id 8BF76140A70; Tue, 16 Jul 2024 23:04:27 +0800 (CST) Received: from P_UKIT01-A7bmah.china.huawei.com (10.48.159.153) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 16 Jul 2024 16:04:26 +0100 From: To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH v9 02/11] EDAC: Add EDAC scrub control driver Date: Tue, 16 Jul 2024 16:03:26 +0100 Message-ID: <20240716150336.2042-3-shiju.jose@huawei.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20240716150336.2042-1-shiju.jose@huawei.com> References: <20240716150336.2042-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.48.159.153] X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) To lhrpeml500006.china.huawei.com (7.191.161.198) X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 25F0D1C0020 X-Stat-Signature: u54hukdkxxtiqmm8y5yinjehe7wudard X-HE-Tag: 1721142270-467429 X-HE-Meta: U2FsdGVkX19/74nHV0dGcBh66NbtEIDAioxIWchKXTvWygbw/qVQ2A8cihItSUq/1fK4AC3MXGw4lOxSegiBlsHranjdCBEN6LFe+Pn2uqQY8b3GU/w+jff58EDLLoMBe1X9mkRZpQieb+BSR9Inr9DuFnMXea/exwWDkd3KmlKtq3YwBim+t9aM0IpsBmP/6o5nVBw2saTIzsob2HUcGRI3Kldri4bVyKCHqYbRXEMkCl7Jy7+0etu3jyKvZoXDlOLxcObx2nOwWa0pfwg8TSEPFqsgIrQyJjIaj9bmr/wqJ0G4PGoaOwWYu4PkaqvD+Jp5eiCGFSOhMea5zkBV6jojIia85ZCC6iObNvQtaf04nRkfrcGLC1flJKm5DJ6JX1orbTB5R6hiIprAK9ZgLoSKnYDezkT/JjPtDEK7scM9iaKs+xZ0fDv9XnRlbS66nVT6Ai9YKOMYfksHYaaX4Z9xkcsm7NrQFoOZ0BX6tW83F1L7mI0YTJsOjw6xw3JjSPX28kbMWvKieXyJzYoS62TtCI3xTn3H0ZnUIjAEkiEIXpjLClnk7rMke8qsFm36nt75967JqHnQ+h8A8FC49PDhrzRTJvFLmylGoMRgMjhO0/sQyD03evBAowDsA2INH1F+EwlKR58a9ynQG0ZsRXqG4oWRCyb9lxYOZU6STyypG+tpFyoQFqJgFY2PyqRn1jmWVdM1jUpDKqVsi7B4IegH55HQqNJVErmww8nyAb1IFdOSVdvwLvv5lWL1mF3SeZ2vjkOtyICeO9qg+pKgzAtq5+78yEemPoQXuHhBTJSxbkP6E97lQ0N1RFHnV/wxKpdoFcHdq+uHTk0Mnprg+mQn2AKU6W4dO1rPxwkxfWIO3RVjVxcG+G32fL4v5kePI5mO+Tcr7SiMDFksTAeCrd2csIuj2vywaNUbsMN9Mi70FrseULfhhIZii46gRf1c9bFMclr3KGWIo4wbqrU ksYkaG15 yeFtOAV/c7PnRQ21ApQM6dM1KM+0sGyIeLn+e38Z7TjdXKAe2yVtrX7ljD3182S0JWnRbxz8m2MBusbdD1vDtn4PBDpGck7kJZM27Yy8J4inl3GRn78gHhrR41Y1BCQjC+BGeVvPm4seLebRMXZCUIxrhIbjdARJ07S+KptRdnm6H2Hzk8UN0fZz/C0JlpNMBI8EuE8Ym7tgcLMKmr6wApNKvYtyqW1BrOoaJTzRhDZ4VCsQeripNb/5f3Cmr12DqiuJkhsj6ZSNuD3pQjODUePlsbRidhn2K5LfOArxAKE+i5sY= 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 generic EDAC scrub control driver supports configuring the memory scrubbers in the system. The device with scrub feature, get the scrub descriptor from the EDAC scrub and registers with the EDAC RAS feature driver, which adds the sysfs scrub control interface. The scrub control attributes are available to the userspace in /sys/bus/edac/devices//scrub/. Generic EDAC scrub driver and the common sysfs scrub interface promotes unambiguous access from the userspace irrespective of the underlying scrub devices. Co-developed-by: Jonathan Cameron Signed-off-by: Jonathan Cameron Signed-off-by: Shiju Jose --- Documentation/ABI/testing/sysfs-edac-scrub | 64 +++++ drivers/edac/Makefile | 2 +- drivers/edac/edac_ras_feature.c | 1 + drivers/edac/edac_scrub.c | 312 +++++++++++++++++++++ include/linux/edac_ras_feature.h | 28 ++ 5 files changed, 406 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-edac-scrub create mode 100755 drivers/edac/edac_scrub.c diff --git a/Documentation/ABI/testing/sysfs-edac-scrub b/Documentation/ABI/testing/sysfs-edac-scrub new file mode 100644 index 000000000000..dd19afd5e165 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-edac-scrub @@ -0,0 +1,64 @@ +What: /sys/bus/edac/devices//scrub +Date: Oct 2024 +KernelVersion: 6.12 +Contact: linux-edac@vger.kernel.org +Description: + The sysfs edac bus devices //scrub subdirectory + belongs to the memory scrub control feature, where + directory corresponds to a device/memory region registered + with the edac scrub driver and thus registered with the + generic edac ras driver too. + +What: /sys/bus/edac/devices//scrub/addr_range_base +Date: Oct 2024 +KernelVersion: 6.12 +Contact: linux-edac@vger.kernel.org +Description: + (RW) The base of the address range of the memory region + to be scrubbed (on-demand scrubbing). + +What: /sys/bus/edac/devices//scrub/addr_range_size +Date: Oct 2024 +KernelVersion: 6.12 +Contact: linux-edac@vger.kernel.org +Description: + (RW) The size of the address range of the memory region + to be scrubbed (on-demand scrubbing). + +What: /sys/bus/edac/devices//scrub/enable_background +Date: Oct 2024 +KernelVersion: 6.12 +Contact: linux-edac@vger.kernel.org +Description: + (RW) Start/Stop background(patrol) scrubbing if supported. + +What: /sys/bus/edac/devices//scrub/enable_on_demand +Date: Oct 2024 +KernelVersion: 6.12 +Contact: linux-edac@vger.kernel.org +Description: + (RW) Start/Stop on-demand scrubbing the memory region + if supported. + +What: /sys/bus/edac/devices//scrub/name +Date: Oct 2024 +KernelVersion: 6.12 +Contact: linux-edac@vger.kernel.org +Description: + (RO) name of the memory scrubber + +What: /sys/bus/edac/devices//scrub/cycle_in_hours_available +Date: Oct 2024 +KernelVersion: 6.12 +Contact: linux-edac@vger.kernel.org +Description: + (RO) Supported range for the scrub cycle in hours by the + memory scrubber. + +What: /sys/bus/edac/devices//scrub/cycle_in_hours +Date: Oct 2024 +KernelVersion: 6.12 +Contact: linux-edac@vger.kernel.org +Description: + (RW) The scrub cycle in hours specified and it must be with in the + supported range by the memory scrubber. diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile index c532b57a6d8a..de56cbd039eb 100644 --- a/drivers/edac/Makefile +++ b/drivers/edac/Makefile @@ -10,7 +10,7 @@ obj-$(CONFIG_EDAC) := edac_core.o edac_core-y := edac_mc.o edac_device.o edac_mc_sysfs.o edac_core-y += edac_module.o edac_device_sysfs.o wq.o -edac_core-y += edac_ras_feature.o +edac_core-y += edac_ras_feature.o edac_scrub.o edac_core-$(CONFIG_EDAC_DEBUG) += debugfs.o diff --git a/drivers/edac/edac_ras_feature.c b/drivers/edac/edac_ras_feature.c index 24a729fea66f..48927f868372 100755 --- a/drivers/edac/edac_ras_feature.c +++ b/drivers/edac/edac_ras_feature.c @@ -36,6 +36,7 @@ static int edac_ras_feat_scrub_init(struct device *parent, { sdata->ops = sfeat->scrub_ops; sdata->private = sfeat->scrub_ctx; + attr_groups[0] = edac_scrub_get_desc(); return 1; } diff --git a/drivers/edac/edac_scrub.c b/drivers/edac/edac_scrub.c new file mode 100755 index 000000000000..0b07eafd3551 --- /dev/null +++ b/drivers/edac/edac_scrub.c @@ -0,0 +1,312 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Generic EDAC scrub driver supports controlling the memory + * scrubbers in the system and the common sysfs scrub interface + * promotes unambiguous access from the userspace. + * + * Copyright (c) 2024 HiSilicon Limited. + */ + +#define pr_fmt(fmt) "EDAC SCRUB: " fmt + +#include + +static ssize_t addr_range_base_show(struct device *ras_feat_dev, + struct device_attribute *attr, + char *buf) +{ + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_scrub_ops *ops = ctx->scrub.ops; + u64 base, size; + int ret; + + ret = ops->read_range(ras_feat_dev->parent, ctx->scrub.private, &base, &size); + if (ret) + return ret; + + return sysfs_emit(buf, "0x%llx\n", base); +} + +static ssize_t addr_range_size_show(struct device *ras_feat_dev, + struct device_attribute *attr, + char *buf) +{ + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_scrub_ops *ops = ctx->scrub.ops; + u64 base, size; + int ret; + + ret = ops->read_range(ras_feat_dev->parent, ctx->scrub.private, &base, &size); + if (ret) + return ret; + + return sysfs_emit(buf, "0x%llx\n", size); +} + +static ssize_t addr_range_base_store(struct device *ras_feat_dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_scrub_ops *ops = ctx->scrub.ops; + u64 base, size; + int ret; + + ret = ops->read_range(ras_feat_dev->parent, ctx->scrub.private, &base, &size); + if (ret) + return ret; + + ret = kstrtou64(buf, 16, &base); + if (ret < 0) + return ret; + + ret = ops->write_range(ras_feat_dev->parent, ctx->scrub.private, base, size); + if (ret) + return ret; + + return len; +} + +static ssize_t addr_range_size_store(struct device *ras_feat_dev, + struct device_attribute *attr, + const char *buf, + size_t len) +{ + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_scrub_ops *ops = ctx->scrub.ops; + u64 base, size; + int ret; + + ret = ops->read_range(ras_feat_dev->parent, ctx->scrub.private, &base, &size); + if (ret) + return ret; + + ret = kstrtou64(buf, 16, &size); + if (ret < 0) + return ret; + + ret = ops->write_range(ras_feat_dev->parent, ctx->scrub.private, base, size); + if (ret) + return ret; + + return len; +} + +static ssize_t enable_background_store(struct device *ras_feat_dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_scrub_ops *ops = ctx->scrub.ops; + bool enable; + int ret; + + ret = kstrtobool(buf, &enable); + if (ret < 0) + return ret; + + ret = ops->set_enabled_bg(ras_feat_dev->parent, ctx->scrub.private, enable); + if (ret) + return ret; + + return len; +} + +static ssize_t enable_background_show(struct device *ras_feat_dev, + struct device_attribute *attr, char *buf) +{ + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_scrub_ops *ops = ctx->scrub.ops; + bool enable; + int ret; + + ret = ops->get_enabled_bg(ras_feat_dev->parent, ctx->scrub.private, &enable); + if (ret) + return ret; + + return sysfs_emit(buf, "%d\n", enable); +} + +static ssize_t enable_on_demand_show(struct device *ras_feat_dev, + struct device_attribute *attr, char *buf) +{ + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_scrub_ops *ops = ctx->scrub.ops; + bool enable; + int ret; + + ret = ops->get_enabled_od(ras_feat_dev->parent, ctx->scrub.private, &enable); + if (ret) + return ret; + + return sysfs_emit(buf, "%d\n", enable); +} + +static ssize_t enable_on_demand_store(struct device *ras_feat_dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_scrub_ops *ops = ctx->scrub.ops; + bool enable; + int ret; + + ret = kstrtobool(buf, &enable); + if (ret < 0) + return ret; + + ret = ops->set_enabled_od(ras_feat_dev->parent, ctx->scrub.private, enable); + if (ret) + return ret; + + return len; +} + +static ssize_t name_show(struct device *ras_feat_dev, + struct device_attribute *attr, char *buf) +{ + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_scrub_ops *ops = ctx->scrub.ops; + int ret; + + ret = ops->get_name(ras_feat_dev->parent, ctx->scrub.private, buf); + if (ret) + return ret; + + return strlen(buf); +} + +static ssize_t cycle_in_hours_show(struct device *ras_feat_dev, struct device_attribute *attr, + char *buf) +{ + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_scrub_ops *ops = ctx->scrub.ops; + u64 val; + int ret; + + ret = ops->cycle_in_hours_read(ras_feat_dev->parent, ctx->scrub.private, &val); + if (ret) + return ret; + + return sysfs_emit(buf, "0x%llx\n", val); +} + +static ssize_t cycle_in_hours_store(struct device *ras_feat_dev, struct device_attribute *attr, + const char *buf, size_t len) +{ + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_scrub_ops *ops = ctx->scrub.ops; + long val; + int ret; + + ret = kstrtol(buf, 10, &val); + if (ret < 0) + return ret; + + ret = ops->cycle_in_hours_write(ras_feat_dev->parent, ctx->scrub.private, val); + if (ret) + return ret; + + return len; +} + +static ssize_t cycle_in_hours_range_show(struct device *ras_feat_dev, + struct device_attribute *attr, + char *buf) +{ + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_scrub_ops *ops = ctx->scrub.ops; + u64 min_schrs, max_schrs; + int ret; + + ret = ops->cycle_in_hours_range(ras_feat_dev->parent, ctx->scrub.private, + &min_schrs, &max_schrs); + if (ret) + return ret; + + return sysfs_emit(buf, "0x%llx-0x%llx\n", min_schrs, max_schrs); +} + +static DEVICE_ATTR_RW(addr_range_base); +static DEVICE_ATTR_RW(addr_range_size); +static DEVICE_ATTR_RW(enable_background); +static DEVICE_ATTR_RW(enable_on_demand); +static DEVICE_ATTR_RO(name); +static DEVICE_ATTR_RW(cycle_in_hours); +static DEVICE_ATTR_RO(cycle_in_hours_range); + +static struct attribute *scrub_attrs[] = { + &dev_attr_addr_range_base.attr, + &dev_attr_addr_range_size.attr, + &dev_attr_enable_background.attr, + &dev_attr_enable_on_demand.attr, + &dev_attr_name.attr, + &dev_attr_cycle_in_hours.attr, + &dev_attr_cycle_in_hours_range.attr, + NULL +}; + +static umode_t scrub_attr_visible(struct kobject *kobj, + struct attribute *a, int attr_id) +{ + struct device *ras_feat_dev = kobj_to_dev(kobj); + struct edac_ras_feat_ctx *ctx; + const struct edac_scrub_ops *ops; + + ctx = dev_get_drvdata(ras_feat_dev); + if (!ctx) + return 0; + + ops = ctx->scrub.ops; + if (a == &dev_attr_addr_range_base.attr || + a == &dev_attr_addr_range_size.attr) { + if (ops->read_range && ops->write_range) + return a->mode; + if (ops->read_range) + return 0444; + return 0; + } + if (a == &dev_attr_enable_background.attr) { + if (ops->set_enabled_bg && ops->get_enabled_bg) + return a->mode; + if (ops->get_enabled_bg) + return 0444; + return 0; + } + if (a == &dev_attr_enable_on_demand.attr) { + if (ops->set_enabled_od && ops->get_enabled_od) + return a->mode; + if (ops->get_enabled_od) + return 0444; + return 0; + } + if (a == &dev_attr_name.attr) + return ops->get_name ? a->mode : 0; + if (a == &dev_attr_cycle_in_hours_range.attr) + return ops->cycle_in_hours_range ? a->mode : 0; + if (a == &dev_attr_cycle_in_hours.attr) { /* Write only makes little sense */ + if (ops->cycle_in_hours_read && ops->cycle_in_hours_write) + return a->mode; + if (ops->cycle_in_hours_read) + return 0444; + return 0; + } + + return 0; +} + +static const struct attribute_group scrub_attr_group = { + .name = "scrub", + .attrs = scrub_attrs, + .is_visible = scrub_attr_visible, +}; + +/** + * edac_scrub_get_desc - get edac scrub's attr descriptor + * + * Returns attribute_group for the scrub feature. + */ +const struct attribute_group *edac_scrub_get_desc(void) +{ + return &scrub_attr_group; +} diff --git a/include/linux/edac_ras_feature.h b/include/linux/edac_ras_feature.h index 000e99141023..462f9ecbf9d4 100755 --- a/include/linux/edac_ras_feature.h +++ b/include/linux/edac_ras_feature.h @@ -19,6 +19,34 @@ enum edac_ras_feat { ras_feat_max }; +/** + * struct scrub_ops - scrub device operations (all elements optional) + * @read_range: read base and offset of scrubbing range. + * @write_range: set the base and offset of the scrubbing range. + * @get_enabled_bg: check if currently performing background scrub. + * @set_enabled_bg: start or stop a bg-scrub. + * @get_enabled_od: check if currently performing on-demand scrub. + * @set_enabled_od: start or stop an on-demand scrub. + * @cycle_in_hours_range: retrieve limits on supported cycle in hours. + * @cycle_in_hours_read: read the scrub cycle in hours. + * @cycle_in_hours_write: set the scrub cycle in hours. + * @get_name: get the memory scrubber's name. + */ +struct edac_scrub_ops { + int (*read_range)(struct device *dev, void *drv_data, u64 *base, u64 *size); + int (*write_range)(struct device *dev, void *drv_data, u64 base, u64 size); + int (*get_enabled_bg)(struct device *dev, void *drv_data, bool *enable); + int (*set_enabled_bg)(struct device *dev, void *drv_data, bool enable); + int (*get_enabled_od)(struct device *dev, void *drv_data, bool *enable); + int (*set_enabled_od)(struct device *dev, void *drv_data, bool enable); + int (*cycle_in_hours_range)(struct device *dev, void *drv_data, u64 *min, u64 *max); + int (*cycle_in_hours_read)(struct device *dev, void *drv_data, u64 *schrs); + int (*cycle_in_hours_write)(struct device *dev, void *drv_data, u64 schrs); + int (*get_name)(struct device *dev, void *drv_data, char *buf); +}; + +const struct attribute_group *edac_scrub_get_desc(void); + struct edac_ecs_ex_info { u16 num_media_frus; }; From patchwork Tue Jul 16 15:03:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13734591 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 79116C3DA49 for ; Tue, 16 Jul 2024 15:04:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A052C6B0088; Tue, 16 Jul 2024 11:04:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 98F0B6B0089; Tue, 16 Jul 2024 11:04:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 794616B008A; Tue, 16 Jul 2024 11:04:34 -0400 (EDT) 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 506396B0088 for ; Tue, 16 Jul 2024 11:04:34 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0993F814C1 for ; Tue, 16 Jul 2024 15:04:34 +0000 (UTC) X-FDA: 82345937268.06.FD4907F Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf30.hostedemail.com (Postfix) with ESMTP id C5FEC8001B for ; Tue, 16 Jul 2024 15:04:31 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.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=1721142233; 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=2jcjSkqONe5TZhUEDfV0bf+oEPjwIE+v25b6UZQDMAE=; b=Hk2Ai0LmDHpMXKd3KmkF9JNhMzOkS9NJhS+DhkUzGGaj6qPJTmt5RnvOLz3B+Cko0oQLn6 zV+sij3s/Xd0tPrv0vRO1wIgkur1481vARQLpKkhu+yA3k4v9oAycyYmeF8EF24lWZZlbL TiOWkaZb8/hcZtCGPKd3jNZ/E9V061Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721142233; a=rsa-sha256; cv=none; b=OBwZY61iNh3jHtL87qD0/rwVDEIku7M6AKKIP+jq5kpceMJL7ceIvE1cnJ+ZBAF6FCaVPD NK2zbYG1OFLnHALCUKpijTE6Unlb+OcAPgmc/J1c3+NVJMlJmU1fSyEyWHrWGfq+iBXOSX 48kcUCYPJxV7MXYru8EUTGPycuAYbdQ= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.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 mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4WNj3D6gGdz67ZDL; Tue, 16 Jul 2024 23:02:16 +0800 (CST) Received: from lhrpeml500006.china.huawei.com (unknown [7.191.161.198]) by mail.maildlp.com (Postfix) with ESMTPS id D5D89140A70; Tue, 16 Jul 2024 23:04:29 +0800 (CST) Received: from P_UKIT01-A7bmah.china.huawei.com (10.48.159.153) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 16 Jul 2024 16:04:28 +0100 From: To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH v9 03/11] EDAC: Add EDAC ECS control driver Date: Tue, 16 Jul 2024 16:03:27 +0100 Message-ID: <20240716150336.2042-4-shiju.jose@huawei.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20240716150336.2042-1-shiju.jose@huawei.com> References: <20240716150336.2042-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.48.159.153] X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) To lhrpeml500006.china.huawei.com (7.191.161.198) X-Stat-Signature: 8rksgco9ppzggpr4q7crgc9hc5z6f3op X-Rspamd-Queue-Id: C5FEC8001B X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1721142271-605894 X-HE-Meta: U2FsdGVkX1+26scvhl/RW4u7kiAXXugJoNjgq4RNFAzakr8WUF92+LPg1sbCd5UyztexklRIEJVB4uKP/Fft54KsPhm1pFoRRJzEitkT74I/ViqjE9cdk8K1ATLRYoA3inmY7LMprlP+hL+snrNVxluYljq0E1Kh/il8e9Cdt94dwEWinDhZE+Dp7IaS/352uZe/QqJiWVq10s6KGqf6WZKJYin1RhONmEAC/XtMKxMkC8hqczqGQHBh+DjQZlY/Fz/eToe6J2hg5+E/lzOfmPU3MCHn6P6B+zT5LWR9FvCSP+GZtG8Zp0RDI5V4Ivofsx0ptGhPMgBQFZfHoihpHMz/eSEcrXQvBNPeJuKQ4rIVFtwXK4GzvYHY/KFe+f6po8pUwoLmj4APjPbarTrKbSNAy6+1IBmO88CkKWgUGoi521Bgskz7CFrxLk/oFLicpyu/ptDN6Z877hTysaFY+Z46Np5QoMoH4zxk/om2xAMCW2gNLuY+AXxzsypAozKKhsgsna1Jzanjn5pYg9Kxu9AhPFCxn7QNcHSOgNJvo9/hit3OAnoTa87IGKoRbkkgkYkUMdkNe26D55FlMo/ZMHPhyq8F2c0Dlg0yN9Dj7xLvSIXuE0LrFUzgWbQQHaaLA7ZjGPJR8ssB1QUez9DQaJ+VkBeWLcYMlR04dP19TH6RlFmB48py0Rj6iV0YVmeOtkXHjrzk0BweG1qEjmlwIv6baFWsl5xMOjPmjuURXxiTvvMpQKNoct57EGSsgZfiSFWCokmZhf9iS0svfSBTNWE7f8MABJn29RQUWkuHrdFPIi9pcO2REPXenf9uOjlv9HtPHehl/ghqdLIt+aZyGaIkdEzER8pVfrSV4N9shcreZkYd3KCaDgreYFKd2JunsSpL1tfy9UTQGO1kTvGx9p1Cwm8Gp94bdbnbPXO0FxT4cVdqY2gyBOlCvGz4qooeOHZXvdw3CPsz6PmEBwP U9WvxDva vhtxtZEKp2PtBGibv1xYGUaLzYjeBS6HVPSlRrwG5sAd74qSsqJdrsbkc+xPulaT977fmOfO1Fuvi3bzZ/77UcpbEJCzlaRzJE77K3eAStgyebyEBQVNV90fKnHwgOH/7StuR/xAc1l2HNq3VJ5PMpvtjIe8IL7AaRlCqRBy4MH1s+8FPClyBk2LiFOKHkuBYsoMbXrWQmmub78DSMWdThVXunw== 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 EDAC ECS (Error Check Scrub) control driver supports configuring the memory device's 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 DDR5 device contains number of memory media FRUs per device. The DDR5 ECS feature and thus the ECS control driver supports configuring the ECS parameters per FRU. The memory devices supports ECS feature register with the EDAC ECS driver and thus with the generic EDAC RAS feature driver, which adds the sysfs ECS control interface. The ECS control attributes are exposed to the userspace in /sys/bus/edac/devices//ecs_fruX/. Generic EDAC ECS driver and the common sysfs ECS interface promotes unambiguous control from the userspace irrespective of the underlying devices, support ECS feature. The support for ECS feature is added separately because the DDR5 ECS feature's control attributes are dissimilar from those of the scrub feature. Note: Documentation can be added if necessary. Co-developed-by: Jonathan Cameron Signed-off-by: Jonathan Cameron Signed-off-by: Shiju Jose --- drivers/edac/Makefile | 2 +- drivers/edac/edac_ecs.c | 396 +++++++++++++++++++++++++++++++ drivers/edac/edac_ras_feature.c | 5 + include/linux/edac_ras_feature.h | 36 +++ 4 files changed, 438 insertions(+), 1 deletion(-) create mode 100755 drivers/edac/edac_ecs.c diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile index de56cbd039eb..c1412c7d3efb 100644 --- a/drivers/edac/Makefile +++ b/drivers/edac/Makefile @@ -10,7 +10,7 @@ obj-$(CONFIG_EDAC) := edac_core.o edac_core-y := edac_mc.o edac_device.o edac_mc_sysfs.o edac_core-y += edac_module.o edac_device_sysfs.o wq.o -edac_core-y += edac_ras_feature.o edac_scrub.o +edac_core-y += edac_ras_feature.o edac_scrub.o edac_ecs.o edac_core-$(CONFIG_EDAC_DEBUG) += debugfs.o diff --git a/drivers/edac/edac_ecs.c b/drivers/edac/edac_ecs.c new file mode 100755 index 000000000000..37dabd053c36 --- /dev/null +++ b/drivers/edac/edac_ecs.c @@ -0,0 +1,396 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * ECS driver supporting controlling on die error check scrub + * (e.g. DDR5 ECS). The common sysfs ECS interface promotes + * unambiguous access from the userspace. + * + * Copyright (c) 2024 HiSilicon Limited. + */ + +#define pr_fmt(fmt) "EDAC ECS: " fmt + +#include + +#define EDAC_ECS_FRU_NAME "ecs_fru" + +enum edac_ecs_attributes { + ecs_log_entry_type, + ecs_log_entry_type_per_dram, + ecs_log_entry_type_per_memory_media, + ecs_mode, + ecs_mode_counts_rows, + ecs_mode_counts_codewords, + ecs_reset, + ecs_name, + ecs_threshold, + ecs_max_attrs +}; + +struct edac_ecs_dev_attr { + struct device_attribute dev_attr; + int fru_id; +}; + +struct edac_ecs_fru_context { + char name[EDAC_RAS_NAME_LEN]; + struct edac_ecs_dev_attr ecs_dev_attr[ecs_max_attrs]; + struct attribute *ecs_attrs[ecs_max_attrs + 1]; + struct attribute_group group; +}; + +struct edac_ecs_context { + u16 num_media_frus; + struct edac_ecs_fru_context *fru_ctxs; +}; + +#define to_ecs_dev_attr(_dev_attr) \ + container_of(_dev_attr, struct edac_ecs_dev_attr, dev_attr) + +static ssize_t log_entry_type_show(struct device *ras_feat_dev, + struct device_attribute *attr, + char *buf) +{ + struct edac_ecs_dev_attr *ecs_dev_attr = to_ecs_dev_attr(attr); + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_ecs_ops *ops = ctx->ecs.ops; + u64 val; + int ret; + + ret = ops->get_log_entry_type(ras_feat_dev->parent, ctx->ecs.private, + ecs_dev_attr->fru_id, &val); + if (ret) + return ret; + + return sysfs_emit(buf, "0x%llx\n", val); +} + +static ssize_t log_entry_type_store(struct device *ras_feat_dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct edac_ecs_dev_attr *ecs_dev_attr = to_ecs_dev_attr(attr); + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_ecs_ops *ops = ctx->ecs.ops; + long val; + int ret; + + ret = kstrtol(buf, 10, &val); + if (ret < 0) + return ret; + + ret = ops->set_log_entry_type(ras_feat_dev->parent, ctx->ecs.private, + ecs_dev_attr->fru_id, val); + if (ret) + return ret; + + return len; +} + +static ssize_t log_entry_type_per_dram_show(struct device *ras_feat_dev, + struct device_attribute *attr, + char *buf) +{ + struct edac_ecs_dev_attr *ecs_dev_attr = to_ecs_dev_attr(attr); + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_ecs_ops *ops = ctx->ecs.ops; + u64 val; + int ret; + + ret = ops->get_log_entry_type_per_dram(ras_feat_dev->parent, ctx->ecs.private, + ecs_dev_attr->fru_id, &val); + if (ret) + return ret; + + return sysfs_emit(buf, "0x%llx\n", val); +} + +static ssize_t log_entry_type_per_memory_media_show(struct device *ras_feat_dev, + struct device_attribute *attr, + char *buf) +{ + struct edac_ecs_dev_attr *ecs_dev_attr = to_ecs_dev_attr(attr); + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_ecs_ops *ops = ctx->ecs.ops; + u64 val; + int ret; + + ret = ops->get_log_entry_type_per_memory_media(ras_feat_dev->parent, + ctx->ecs.private, + ecs_dev_attr->fru_id, &val); + if (ret) + return ret; + + return sysfs_emit(buf, "0x%llx\n", val); +} + +static ssize_t mode_show(struct device *ras_feat_dev, + struct device_attribute *attr, + char *buf) +{ + struct edac_ecs_dev_attr *ecs_dev_attr = to_ecs_dev_attr(attr); + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_ecs_ops *ops = ctx->ecs.ops; + u64 val; + int ret; + + ret = ops->get_mode(ras_feat_dev->parent, ctx->ecs.private, + ecs_dev_attr->fru_id, &val); + if (ret) + return ret; + + return sysfs_emit(buf, "0x%llx\n", val); +} + +static ssize_t mode_store(struct device *ras_feat_dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct edac_ecs_dev_attr *ecs_dev_attr = to_ecs_dev_attr(attr); + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_ecs_ops *ops = ctx->ecs.ops; + long val; + int ret; + + ret = kstrtol(buf, 10, &val); + if (ret < 0) + return ret; + + ret = ops->set_mode(ras_feat_dev->parent, ctx->ecs.private, + ecs_dev_attr->fru_id, val); + if (ret) + return ret; + + return len; +} + +static ssize_t mode_counts_rows_show(struct device *ras_feat_dev, + struct device_attribute *attr, + char *buf) +{ + struct edac_ecs_dev_attr *ecs_dev_attr = to_ecs_dev_attr(attr); + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_ecs_ops *ops = ctx->ecs.ops; + u64 val; + int ret; + + ret = ops->get_mode_counts_rows(ras_feat_dev->parent, ctx->ecs.private, + ecs_dev_attr->fru_id, &val); + if (ret) + return ret; + + return sysfs_emit(buf, "0x%llx\n", val); +} + +static ssize_t mode_counts_codewords_show(struct device *ras_feat_dev, + struct device_attribute *attr, + char *buf) +{ + struct edac_ecs_dev_attr *ecs_dev_attr = to_ecs_dev_attr(attr); + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_ecs_ops *ops = ctx->ecs.ops; + u64 val; + int ret; + + ret = ops->get_mode_counts_codewords(ras_feat_dev->parent, ctx->ecs.private, + ecs_dev_attr->fru_id, &val); + if (ret) + return ret; + + return sysfs_emit(buf, "0x%llx\n", val); +} + +static ssize_t reset_store(struct device *ras_feat_dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct edac_ecs_dev_attr *ecs_dev_attr = to_ecs_dev_attr(attr); + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_ecs_ops *ops = ctx->ecs.ops; + long val; + int ret; + + ret = kstrtol(buf, 10, &val); + if (ret < 0) + return ret; + + ret = ops->reset(ras_feat_dev->parent, ctx->ecs.private, + ecs_dev_attr->fru_id, val); + if (ret) + return ret; + + return len; +} + +static ssize_t name_show(struct device *ras_feat_dev, + struct device_attribute *attr, char *buf) +{ + struct edac_ecs_dev_attr *ecs_dev_attr = to_ecs_dev_attr(attr); + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_ecs_ops *ops = ctx->ecs.ops; + int ret; + + ret = ops->get_name(ras_feat_dev->parent, ctx->ecs.private, + ecs_dev_attr->fru_id, buf); + if (ret) + return ret; + + return strlen(buf); +} + +static ssize_t threshold_show(struct device *ras_feat_dev, + struct device_attribute *attr, char *buf) +{ + struct edac_ecs_dev_attr *ecs_dev_attr = to_ecs_dev_attr(attr); + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_ecs_ops *ops = ctx->ecs.ops; + int ret; + u64 val; + + ret = ops->get_threshold(ras_feat_dev->parent, ctx->ecs.private, + ecs_dev_attr->fru_id, &val); + if (ret) + return ret; + + return sysfs_emit(buf, "0x%llx\n", val); +} + +static ssize_t threshold_store(struct device *ras_feat_dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct edac_ecs_dev_attr *ecs_dev_attr = to_ecs_dev_attr(attr); + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_ecs_ops *ops = ctx->ecs.ops; + long val; + int ret; + + ret = kstrtol(buf, 10, &val); + if (ret < 0) + return ret; + + ret = ops->set_threshold(ras_feat_dev->parent, ctx->ecs.private, + ecs_dev_attr->fru_id, val); + if (ret) + return ret; + + return len; +} + +static umode_t ecs_attr_visible(struct kobject *kobj, + struct attribute *a, int attr_id) +{ + struct device *ras_feat_dev = kobj_to_dev(kobj); + struct edac_ras_feat_ctx *ctx = dev_get_drvdata(ras_feat_dev); + const struct edac_ecs_ops *ops = ctx->ecs.ops; + + switch (attr_id) { + case ecs_log_entry_type: + if (ops->get_log_entry_type && ops->set_log_entry_type) + return a->mode; + if (ops->get_log_entry_type) + return 0444; + return 0; + case ecs_log_entry_type_per_dram: + return ops->get_log_entry_type_per_dram ? a->mode : 0; + case ecs_log_entry_type_per_memory_media: + return ops->get_log_entry_type_per_memory_media ? a->mode : 0; + case ecs_mode: + if (ops->get_mode && ops->set_mode) + return a->mode; + if (ops->get_mode) + return 0444; + return 0; + case ecs_mode_counts_rows: + return ops->get_mode_counts_rows ? a->mode : 0; + case ecs_mode_counts_codewords: + return ops->get_mode_counts_codewords ? a->mode : 0; + case ecs_reset: + return ops->reset ? a->mode : 0; + case ecs_name: + return ops->get_name ? a->mode : 0; + case ecs_threshold: + if (ops->get_threshold && ops->set_threshold) + return a->mode; + if (ops->get_threshold) + return 0444; + return 0; + default: + return 0; + } +} + +#define EDAC_ECS_ATTR_RO(_name, _fru_id) \ + ((struct edac_ecs_dev_attr) { .dev_attr = __ATTR_RO(_name), \ + .fru_id = _fru_id }) + +#define EDAC_ECS_ATTR_WO(_name, _fru_id) \ + ((struct edac_ecs_dev_attr) { .dev_attr = __ATTR_WO(_name), \ + .fru_id = _fru_id }) + +#define EDAC_ECS_ATTR_RW(_name, _fru_id) \ + ((struct edac_ecs_dev_attr) { .dev_attr = __ATTR_RW(_name), \ + .fru_id = _fru_id }) + +static int ecs_create_desc(struct device *ecs_dev, + const struct attribute_group **attr_groups, + u16 num_media_frus) +{ + struct edac_ecs_context *ecs_ctx; + u32 fru; + + ecs_ctx = devm_kzalloc(ecs_dev, sizeof(*ecs_ctx), GFP_KERNEL); + if (!ecs_ctx) + return -ENOMEM; + + ecs_ctx->num_media_frus = num_media_frus; + ecs_ctx->fru_ctxs = devm_kcalloc(ecs_dev, num_media_frus, + sizeof(*ecs_ctx->fru_ctxs), + GFP_KERNEL); + if (!ecs_ctx->fru_ctxs) + return -ENOMEM; + + for (fru = 0; fru < num_media_frus; fru++) { + struct edac_ecs_fru_context *fru_ctx = &ecs_ctx->fru_ctxs[fru]; + struct attribute_group *group = &fru_ctx->group; + int i; + + fru_ctx->ecs_dev_attr[0] = EDAC_ECS_ATTR_RW(log_entry_type, fru); + fru_ctx->ecs_dev_attr[1] = EDAC_ECS_ATTR_RO(log_entry_type_per_dram, fru); + fru_ctx->ecs_dev_attr[2] = EDAC_ECS_ATTR_RO(log_entry_type_per_memory_media, fru); + fru_ctx->ecs_dev_attr[3] = EDAC_ECS_ATTR_RW(mode, fru); + fru_ctx->ecs_dev_attr[4] = EDAC_ECS_ATTR_RO(mode_counts_rows, fru); + fru_ctx->ecs_dev_attr[5] = EDAC_ECS_ATTR_RO(mode_counts_codewords, fru); + fru_ctx->ecs_dev_attr[6] = EDAC_ECS_ATTR_WO(reset, fru); + fru_ctx->ecs_dev_attr[7] = EDAC_ECS_ATTR_RO(name, fru); + fru_ctx->ecs_dev_attr[8] = EDAC_ECS_ATTR_RW(threshold, fru); + for (i = 0; i < ecs_max_attrs; i++) + fru_ctx->ecs_attrs[i] = &fru_ctx->ecs_dev_attr[i].dev_attr.attr; + + sprintf(fru_ctx->name, "%s%d", EDAC_ECS_FRU_NAME, fru); + group->name = fru_ctx->name; + group->attrs = fru_ctx->ecs_attrs; + group->is_visible = ecs_attr_visible; + + attr_groups[fru] = group; + } + + return 0; +} + +/** + * edac_ecs_get_desc - get edac ecs descriptors + * @ecs_dev: client ecs device + * @attr_groups: pointer to attrribute group container + * @num_media_frus: number of media FRUs in the device + * + * Returns 0 on success, error otherwise. + */ +int edac_ecs_get_desc(struct device *ecs_dev, + const struct attribute_group **attr_groups, + u16 num_media_frus) +{ + if (!ecs_dev || !attr_groups || !num_media_frus) + return -EINVAL; + + return ecs_create_desc(ecs_dev, attr_groups, num_media_frus); +} diff --git a/drivers/edac/edac_ras_feature.c b/drivers/edac/edac_ras_feature.c index 48927f868372..a02ffbcc1c1e 100755 --- a/drivers/edac/edac_ras_feature.c +++ b/drivers/edac/edac_ras_feature.c @@ -47,10 +47,15 @@ static int edac_ras_feat_ecs_init(struct device *parent, const struct attribute_group **attr_groups) { int num = efeat->ecs_info.num_media_frus; + int ret; edata->ops = efeat->ecs_ops; edata->private = efeat->ecs_ctx; + ret = edac_ecs_get_desc(parent, attr_groups, num); + if (ret) + return ret; + return num; } diff --git a/include/linux/edac_ras_feature.h b/include/linux/edac_ras_feature.h index 462f9ecbf9d4..153f8a3557f1 100755 --- a/include/linux/edac_ras_feature.h +++ b/include/linux/edac_ras_feature.h @@ -47,10 +47,46 @@ struct edac_scrub_ops { const struct attribute_group *edac_scrub_get_desc(void); +/** + * struct ecs_ops - ECS device operations (all elements optional) + * @get_log_entry_type: read the log entry type value. + * @set_log_entry_type: set the log entry type value. + * @get_log_entry_type_per_dram: read the log entry type per dram value. + * @get_log_entry_type_memory_media: read the log entry type per memory media value. + * @get_mode: read the mode value. + * @set_mode: set the mode value. + * @get_mode_counts_rows: read the mode counts rows value. + * @get_mode_counts_codewords: read the mode counts codewords value. + * @reset: reset the ECS counter. + * @get_threshold: read the threshold value. + * @set_threshold: set the threshold value. + * @get_name: get the ECS's name. + */ +struct edac_ecs_ops { + int (*get_log_entry_type)(struct device *dev, void *drv_data, int fru_id, u64 *val); + int (*set_log_entry_type)(struct device *dev, void *drv_data, int fru_id, u64 val); + int (*get_log_entry_type_per_dram)(struct device *dev, void *drv_data, + int fru_id, u64 *val); + int (*get_log_entry_type_per_memory_media)(struct device *dev, void *drv_data, + int fru_id, u64 *val); + int (*get_mode)(struct device *dev, void *drv_data, int fru_id, u64 *val); + int (*set_mode)(struct device *dev, void *drv_data, int fru_id, u64 val); + int (*get_mode_counts_rows)(struct device *dev, void *drv_data, int fru_id, u64 *val); + int (*get_mode_counts_codewords)(struct device *dev, void *drv_data, int fru_id, u64 *val); + int (*reset)(struct device *dev, void *drv_data, int fru_id, u64 val); + int (*get_threshold)(struct device *dev, void *drv_data, int fru_id, u64 *threshold); + int (*set_threshold)(struct device *dev, void *drv_data, int fru_id, u64 threshold); + int (*get_name)(struct device *dev, void *drv_data, int fru_id, char *buf); +}; + struct edac_ecs_ex_info { u16 num_media_frus; }; +int edac_ecs_get_desc(struct device *ecs_dev, + const struct attribute_group **attr_groups, + u16 num_media_frus); + /* * EDAC RAS feature information structure */ From patchwork Tue Jul 16 15:03:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13734592 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 773F4C3DA59 for ; Tue, 16 Jul 2024 15:04:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 576526B008A; Tue, 16 Jul 2024 11:04:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B0C46B008C; Tue, 16 Jul 2024 11:04:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 28C0D6B0092; Tue, 16 Jul 2024 11:04:37 -0400 (EDT) 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 03CF16B008A for ; Tue, 16 Jul 2024 11:04:36 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 98B281A1818 for ; Tue, 16 Jul 2024 15:04:36 +0000 (UTC) X-FDA: 82345937352.26.E8C046A Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf03.hostedemail.com (Postfix) with ESMTP id 7A6C120033 for ; Tue, 16 Jul 2024 15:04:34 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; 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; 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=1721142244; 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=C0cGonjd6hJklizBwtBBRJi2fZfEjByZNwqfOYbfTPw=; b=xedq9hqLl19Fo2cxkP0oCwEFM4GVkcIKlAqnK6ytYNCuPtZuSQDR/7IyM1Y5ZAXGsHXJzq 52XGUiuTtiqRxinRiRA8xp/NDw0L758M/s+mvp/DH9KCoxdIDWdfGNdlFd50PatwKe+SKs 4pd0vnxAiwVtx9NYlUSSzVpqPd7qce0= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; 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; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721142244; a=rsa-sha256; cv=none; b=lnLm75wukRcHL5OV1ezDaLAicWaxLKzIex2Zgrk/oa9cuQ4EPjbDEybbW8OZ8yoiCA8pS4 o0xd7DXMKL2013K5Okdd8LVi1e+R9Hv/RX3/+18cy4XT6iHYAcPxhRJ5GK3SwSjnOE7/3h IvJ+XPdxwfP/IsKYeAqSROjZOI+uFVA= Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4WNj4N23ljz6JB8B; Tue, 16 Jul 2024 23:03:16 +0800 (CST) Received: from lhrpeml500006.china.huawei.com (unknown [7.191.161.198]) by mail.maildlp.com (Postfix) with ESMTPS id 14F661406AE; Tue, 16 Jul 2024 23:04:32 +0800 (CST) Received: from P_UKIT01-A7bmah.china.huawei.com (10.48.159.153) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 16 Jul 2024 16:04:30 +0100 From: To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH v9 04/11] cxl/mbox: Add GET_SUPPORTED_FEATURES mailbox command Date: Tue, 16 Jul 2024 16:03:28 +0100 Message-ID: <20240716150336.2042-5-shiju.jose@huawei.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20240716150336.2042-1-shiju.jose@huawei.com> References: <20240716150336.2042-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.48.159.153] X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) To lhrpeml500006.china.huawei.com (7.191.161.198) X-Stat-Signature: r4wrqgqmmj7pnt78985oye4qrfit3n5q X-Rspam-User: X-Rspamd-Queue-Id: 7A6C120033 X-Rspamd-Server: rspam02 X-HE-Tag: 1721142274-656279 X-HE-Meta: U2FsdGVkX19o7Xuu+gqhtYRNZ2jVQiE+H4Y6uJhfmnCkVxrWvVNDh4Ss+sft/xg0rjtbcsmM6HZ7nWCn41C2JkdqcMSrbRoJn1UgD/hAs36QsWLyvfTbnZGGtswSGzMoRaP4RFGj8Zsy25hXIU5CIt4Ziz/adLO16G1Gu9P4ss0bBt1rcrL12ciWexE3QKzuDL/sCspLjUQV8cUFJCO1nY0gshoHgZXjX1xCEqZoRa+jl3sfL3NK8XBnTN8NLnuhfIYmXHCExdfrXQFCesL6f+Jvnm/CvIKGJsjkcwV4L12WhTTDMQkDIjMWEfRTAHFhC3XSFO3YgIl8zq2EEKsmKtPoo9vqxBXbiYR9qYIVQ6tMQA51JOV0asuEyvdGBlLcpQvzZeVHEOThLfUZslKlNd+xFfE1oe4W9kCgN2poDebJuYGPm6rlRZOfiHd2ptqC9HGo93fmN20t2HKIG+tzM62OpXj4+OC/ngmULqdISO5rSfSEt1/USJtnLxITN0aSuKXwRaYfaXQxEB6AuSW93sFNmayGGQiCk0hOaujB3efDLM5P/6c0KIg6Hi/KRFvGiRlvimvH4DvjL55AT89BpnFzaVUco7iiqxyrKGSAbuumLuwU755W1PsNP7L0uI8lC3nfURTlG+RkYRBvpC6QfjwNn6hGee6yYqEjiJMMQyRnAJ8DBg4435OehOFM1ZXt9JknqzJiWbjdXSo4Vk009SLMuJCnsDiSLdF2UD8FFh6t46MidyzUnzNhxBGe4o467PhOd8VfT2UWX1t54u8O+7l2i16oZKbBN+fndN4aRXs/qwzfof9tVTYmSonmAf0r36RVwPT5pcyA6Qy3T9QENq5Y+A0OdbZZWiD8YJPJpnU1p94BI7gSh9f6F40azyVScpkteZqsuMfQTT3rYQ4jv+8EBdGvZP2Hf9lz8V6EPCiq54MWVx1/7d01DiyLgahwkGhNixB1U5jmljKuXKy Kw19Owoc 3UPIit2b17zeWttozJqh9enwGovksOE8odzZiRw5IKH01Jpt7Hs/JufS+Yrdl9DLBkN9Kzt2oFBYFBUHdL9IEU8xeTkX/pQXHpEfqq3EgQk9SKqqd4xbdXlDA8oc7FcStzAO1vrfHmKKMPENVOgBZMXj9JoPjKc3iBOnPJc/jhmFtd+1XwAQLGC7PNTtssr4xsLoGSv38wlqUQhS/ZX508yoxefqwOFF5IsijrVqcBjTwnwUXy9x6mumglyWL+4IPK6OvQdWpMR22ntI= 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.1 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 | 27 ++++++++++++++++++ drivers/cxl/cxlmem.h | 61 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index 2626f3fff201..9b9b1d26454e 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -1324,6 +1324,33 @@ 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, + u32 count, u16 start_index, + struct cxl_mbox_get_supp_feats_out *feats_out) +{ + struct cxl_mbox_get_supp_feats_in pi; + struct cxl_mbox_cmd mbox_cmd; + int rc; + + pi.count = cpu_to_le32(count); + pi.start_index = cpu_to_le16(start_index); + + mbox_cmd = (struct cxl_mbox_cmd) { + .opcode = CXL_MBOX_OP_GET_SUPPORTED_FEATURES, + .size_in = sizeof(pi), + .payload_in = &pi, + .size_out = count, + .payload_out = feats_out, + .min_out = sizeof(*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 19aba81cdf13..b0e1565b9d2e 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -530,6 +530,7 @@ enum cxl_opcode { CXL_MBOX_OP_GET_LOG_CAPS = 0x0402, CXL_MBOX_OP_CLEAR_LOG = 0x0403, CXL_MBOX_OP_GET_SUP_LOG_SUBLIST = 0x0405, + 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, @@ -699,6 +700,63 @@ struct cxl_mbox_set_timestamp_in { } __packed; +/* + * Get Supported Features CXL 3.1 Spec 8.2.9.6.1 + */ + +/* + * Get Supported Features input payload + * CXL rev 3.1 section 8.2.9.6.1 Table 8-95 + */ +struct cxl_mbox_get_supp_feats_in { + __le32 count; + __le16 start_index; + u8 rsvd[2]; +} __packed; + +/* + * Get Supported Features Supported Feature Entry + * CXL rev 3.1 section 8.2.9.6.1 Table 8-97 + */ +/* 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) +#define CXL_FEAT_ENTRY_FLAG_PERSIST_ACROSS_FIRMWARE_UPDATE BIT(4) +#define CXL_FEAT_ENTRY_FLAG_SUPPORT_DEFAULT_SELECTION BIT(5) +#define CXL_FEAT_ENTRY_FLAG_SUPPORT_SAVED_SELECTION BIT(6) + +enum cxl_feat_attr_value_persistence { + CXL_FEAT_ATTR_VALUE_PERSISTENCE_NONE, + CXL_FEAT_ATTR_VALUE_PERSISTENCE_CXL_RESET, + CXL_FEAT_ATTR_VALUE_PERSISTENCE_HOT_RESET, + CXL_FEAT_ATTR_VALUE_PERSISTENCE_WARM_RESET, + CXL_FEAT_ATTR_VALUE_PERSISTENCE_COLD_RESET, + CXL_FEAT_ATTR_VALUE_PERSISTENCE_MAX +}; + +struct cxl_mbox_supp_feat_entry { + uuid_t uuid; + __le16 index; + __le16 get_size; + __le16 set_size; + __le32 attr_flags; + u8 get_version; + u8 set_version; + __le16 set_effects; + u8 rsvd[18]; +} __packed; + +/* + * Get Supported Features output payload + * CXL rev 3.1 section 8.2.9.6.1 Table 8-96 + */ +struct cxl_mbox_get_supp_feats_out { + __le16 nr_entries; + __le16 nr_supported; + u8 rsvd[4]; + 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; @@ -830,6 +888,9 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd, enum cxl_event_type event_type, const uuid_t *uuid, union cxl_event *evt); int cxl_set_timestamp(struct cxl_memdev_state *mds); +int cxl_get_supported_features(struct cxl_memdev_state *mds, + u32 count, u16 start_index, + struct cxl_mbox_get_supp_feats_out *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 Tue Jul 16 15:03:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13734593 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 77FC0C3DA49 for ; Tue, 16 Jul 2024 15:04:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF0106B0092; Tue, 16 Jul 2024 11:04:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AA0906B0093; Tue, 16 Jul 2024 11:04:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8CB4E6B0095; Tue, 16 Jul 2024 11:04:39 -0400 (EDT) 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 681F46B0092 for ; Tue, 16 Jul 2024 11:04:39 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E7D3A40602 for ; Tue, 16 Jul 2024 15:04:38 +0000 (UTC) X-FDA: 82345937436.09.4851B3F Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf22.hostedemail.com (Postfix) with ESMTP id DF098C0031 for ; Tue, 16 Jul 2024 15:04:36 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf22.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=1721142233; 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=emuOm0QizK0fUMnK500USG2lwp1vJ2vFsDbBWWUOs04=; b=Uxk41nZNRVgZdmDMBr1Fm+kXdsTidlLL5un5o6dmL/AtjDjXnA9O95QvTpo3pdIZyuoWgN h5r/vyVk2fdf3K77BFCP6ae8+QWALQHrDCsJUYN+uS3vS55e59ivqEnk5UCWEx0gkRRr4p CEn2g6zWikt7yW8PywIlN+iRrckdZPA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721142233; a=rsa-sha256; cv=none; b=nrQAQNpD6IsNO404OmNcf+51qXVsgwoy5EashrNkuCiGL1lltX7sVlGVKkxJYezDqocq17 ylRiPLQ/FNTjZBPv9HLGKe1dgzy03V5iOJIehcHuc8PitG/N5RYquXzI9frPVlvHp3+3ee 0QxrofFQMhPuS2qKbbUM2DZjad9Ji4I= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf22.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4WNj3K4z60z6K96J; Tue, 16 Jul 2024 23:02:21 +0800 (CST) Received: from lhrpeml500006.china.huawei.com (unknown [7.191.161.198]) by mail.maildlp.com (Postfix) with ESMTPS id 9F548140B39; Tue, 16 Jul 2024 23:04:34 +0800 (CST) Received: from P_UKIT01-A7bmah.china.huawei.com (10.48.159.153) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 16 Jul 2024 16:04:32 +0100 From: To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH v9 05/11] cxl/mbox: Add GET_FEATURE mailbox command Date: Tue, 16 Jul 2024 16:03:29 +0100 Message-ID: <20240716150336.2042-6-shiju.jose@huawei.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20240716150336.2042-1-shiju.jose@huawei.com> References: <20240716150336.2042-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.48.159.153] X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) To lhrpeml500006.china.huawei.com (7.191.161.198) X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DF098C0031 X-Stat-Signature: oup4jsntg39ebn3hezyrbmabbiwadexp X-Rspam-User: X-HE-Tag: 1721142276-690524 X-HE-Meta: U2FsdGVkX1/RkqIGIUzF55UzhxwWN5zQEff6iWriLI31cp0+lZBX/QI9DylGqGvWRIYnLuFv//XJjSNHzgyTYFmJI1IOH+/x4OccJUNi2dQxYjs29NF0+YhpIRdUgYOImCWbzPLlX3Kan9rMsBRQpBwKiE72OMKw9L+EU3N/qTi5mxqJCD5S/bTgvsAE1PM1UyQ3aHkuo2Zlphcn/C/h3N2OeFNdrsf2A7b6Jr5zp36/0pDLbNjLoaB+H/VzhfP3Dp993H+VD0+h9NBBJKXhWmiBaXrLMvasdDN1Xl5JEOPsgHqEllJ11ClFriwBcyG4MyGTdxW+iTSkjQqEncAnRrMvt2k5vHb6dNfvhLLPTRnX9BTang6Gi6icXfdX7omy8Kv+79ndsAKb7Ia09Kzy/hefy+TIJBHfKYnWXeDlJycE5RwvDyJBE7QmxKjuolXKTwB4eQQ6k8LbZ2CarFA+9uV8k+m4ZtQCW6jBiCfxWE9wt2jbZH4AcfsamFXRfsOAm/F47W68RIFQ4dmM0Wy2m6AyWu4LKk+QpVAxJmPti64PpVLDKzMAZ7Z07XCNy3JQGT578BKP2D1phkFk9ybg5dKG2QQUlL2eBYsE3VKBvl1BYDFvJzd9pncfak9PV2WLSELhzkM1KcZKPJEX5YYfB40sLfRWTJPHob0V2uvLF73lM/1hb35s7H2/ubNhsGjqZma/MwZ92HZPtXiYDg6UMubo+2E4B2ndzwBzmuwMN5k0zK3+yWTSO88fh7Mz7pX30KQ2ETQgcI9q8ocNHNW6x2q3jyzgxFaNQodLmDOjuumPQXYVbmM43bHwdJnXrCp+Yr5oTs+wrM2mWZr+6QSRdkjipFN903YLYO+D7u3mxelUV2vXAJKcHHBVKOUHqMyX0PyJYEoutNH0NUQMNsRToMrjEx7vwjDiEojXUxJSS2LL38WoohgBKVqMv4DJDW5FcFo4eepNDZyVV6e12VW 3zcnYl4A 0YTN6XrqRFK1smBHBaqIOOZihz1rHP5U5DuzT3WHApb40SKlMNviDdWAcTxxZ6+j4lMpgYbMW9pAyD1T6WKHdLfNpfyg4JNl4Z7oXnu3jVTolYdvVRN+R/G1TUNDagCTZLMCQvZhE0kPOPAfrW+yxBsP3vrH31If4B36O0VRQeqLGhWFmfnxmHmmbS1C1D4qBQbdjsSJr0XkZYDB801LXcZHCi6eJbsf7TgYlOfQoxRj1PfCeF0n30TBJPL7aIdokcMuZTpK4Oo0PitY= 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.1 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 | 37 +++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 27 +++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index 9b9b1d26454e..b1eeed508459 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -1351,6 +1351,43 @@ int cxl_get_supported_features(struct cxl_memdev_state *mds, } EXPORT_SYMBOL_NS_GPL(cxl_get_supported_features, CXL); +size_t cxl_get_feature(struct cxl_memdev_state *mds, + const uuid_t feat_uuid, void *feat_out, + size_t feat_out_size, + enum cxl_get_feat_selection selection) +{ + size_t data_to_rd_size, size_out; + struct cxl_mbox_get_feat_in pi; + struct cxl_mbox_cmd mbox_cmd; + size_t data_rcvd_size = 0; + int rc; + + size_out = min(feat_out_size, mds->payload_size); + pi.uuid = feat_uuid; + pi.selection = selection; + do { + data_to_rd_size = min(feat_out_size - data_rcvd_size, mds->payload_size); + pi.offset = cpu_to_le16(data_rcvd_size); + pi.count = cpu_to_le16(data_to_rd_size); + + mbox_cmd = (struct cxl_mbox_cmd) { + .opcode = CXL_MBOX_OP_GET_FEATURE, + .size_in = sizeof(pi), + .payload_in = &pi, + .size_out = size_out, + .payload_out = feat_out + data_rcvd_size, + .min_out = data_to_rd_size, + }; + rc = cxl_internal_send_cmd(mds, &mbox_cmd); + if (rc < 0 || mbox_cmd.size_out == 0) + return 0; + data_rcvd_size += mbox_cmd.size_out; + } while (data_rcvd_size < feat_out_size); + + return data_rcvd_size; +} +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 b0e1565b9d2e..25698a6fbe66 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -531,6 +531,7 @@ enum cxl_opcode { CXL_MBOX_OP_CLEAR_LOG = 0x0403, CXL_MBOX_OP_GET_SUP_LOG_SUBLIST = 0x0405, 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, @@ -757,6 +758,28 @@ struct cxl_mbox_get_supp_feats_out { struct cxl_mbox_supp_feat_entry feat_entries[]; } __packed; +/* + * Get Feature CXL 3.1 Spec 8.2.9.6.2 + */ + +/* + * Get Feature input payload + * CXL rev 3.1 section 8.2.9.6.2 Table 8-99 + */ +enum cxl_get_feat_selection { + CXL_GET_FEAT_SEL_CURRENT_VALUE, + CXL_GET_FEAT_SEL_DEFAULT_VALUE, + CXL_GET_FEAT_SEL_SAVED_VALUE, + 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; @@ -891,6 +914,10 @@ int cxl_set_timestamp(struct cxl_memdev_state *mds); int cxl_get_supported_features(struct cxl_memdev_state *mds, u32 count, u16 start_index, struct cxl_mbox_get_supp_feats_out *feats_out); +size_t cxl_get_feature(struct cxl_memdev_state *mds, + const uuid_t feat_uuid, void *feat_out, + size_t feat_out_size, + enum cxl_get_feat_selection selection); 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 Tue Jul 16 15:03:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13734594 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 7F17BC3DA49 for ; Tue, 16 Jul 2024 15:04:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 87E0A6B0093; Tue, 16 Jul 2024 11:04:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 807F66B0095; Tue, 16 Jul 2024 11:04:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 683136B0096; Tue, 16 Jul 2024 11:04:41 -0400 (EDT) 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 4760B6B0093 for ; Tue, 16 Jul 2024 11:04:41 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id ECF6B1212A3 for ; Tue, 16 Jul 2024 15:04:40 +0000 (UTC) X-FDA: 82345937520.22.037D5B2 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf10.hostedemail.com (Postfix) with ESMTP id E9EB1C0021 for ; Tue, 16 Jul 2024 15:04:38 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; spf=pass (imf10.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=1721142260; 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=YMIqX1krpZfca2bDoM0Co7MTbbiSb4dospFOevbcvPs=; b=2Qkfvz7Q+qiDyafYfN7h/UTpD2jHT5z0+AJsreuILWzIgJZ2a6W7tqikFNpS340hYCjOFK EcY7beUjY3NRG15F+wWRvcMgteYB2xXUkatB6wNEN2ChmMCv15IUE96PH5kK5T5NVlm8ya RQVSbb527APVnoEBwTZQzdGjOV86F0o= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; spf=pass (imf10.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=1721142260; a=rsa-sha256; cv=none; b=f/OYcsINx8Yg+74tMWoxA8yXOEzYeS68f+Lh7YRHWlgiYhiJPFzTU85E3a2O7rctnsd3U+ NaokLSSHGrXxsWUAptlo3epjEjusDs6amDdKUqDIzQqhjHnzQrjxQwStkSXGtrUyZuoEzU p7vuMpZvCm7J6woJmiiXAjL2hcKHRKM= Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4WNj3N0F6Gz6K8wS; Tue, 16 Jul 2024 23:02:24 +0800 (CST) Received: from lhrpeml500006.china.huawei.com (unknown [7.191.161.198]) by mail.maildlp.com (Postfix) with ESMTPS id F038B1400CF; Tue, 16 Jul 2024 23:04:36 +0800 (CST) Received: from P_UKIT01-A7bmah.china.huawei.com (10.48.159.153) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 16 Jul 2024 16:04:35 +0100 From: To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH v9 06/11] cxl/mbox: Add SET_FEATURE mailbox command Date: Tue, 16 Jul 2024 16:03:30 +0100 Message-ID: <20240716150336.2042-7-shiju.jose@huawei.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20240716150336.2042-1-shiju.jose@huawei.com> References: <20240716150336.2042-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.48.159.153] X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) To lhrpeml500006.china.huawei.com (7.191.161.198) X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: E9EB1C0021 X-Stat-Signature: bxh8179jyut56eyp6mr1zs8eiubuhya1 X-HE-Tag: 1721142278-863164 X-HE-Meta: U2FsdGVkX1+69lNUIJtE2f9YEiPPYvSGcDzyGCV8RgCTLtrxmOwPK8Ct7sZb1zD2aYIHq33W6DBrIFqODwImZH+cdiQCrPBYMR0SGg6j4VuQlAldAw5z57Q4crxF0taWsx6NPcSf+BIPRfUf3nrvPkfxEvOis5AnyZAQZgpEYsov9RbVyO6zXm1H4rNgv/zYg3OBJITwZHmd5RS5TiR2rIzeQngnunooFgyzNvcKqzN7PoZuARqS/t6l3KSQrusd4fH2Xd2FnWjNfXtJVkEkwWlJ6ACgQ7lLX2RnLZLwF2GxpdLyC0Qi1hWrc9MsjaUc8BU/4SLk1GcxQXysVEe8B6r19q8NtvsHqArQsncTrb4j8U+sDnIiQ5p6XMAJfu3pNBw3tJtmyB3XLM7LmAApiXZbNSJ6Te2JghybZ0wKyCY7YqWrloQWDGeeRhT+Fo8rhCQbW2zbzqlUUZbRHJX2LduPWh/21d/zyeJlLe93JuvXbZzps+8jJnoETSsrhsZg0OBl0pYfuQConFroQOLIJ71+ZPhXKW4rdbSl3fIVJSllmahpy09i9pb0AApwPyyAd2dkVpSK8lEeliO7cJBTbsSWO4+T6mqDRqyC/KBfWHT91741nreojwr0W/piXRfdb8NY+/DzWp4oAfddyeDpymR9qTWXFkrDNsskOB96niQdxlhXMYRqWWZxqRQemdiEDJIH/KuDo2fpVjaCc17qwAibEvufc3XGpfHEBnhoegtWhsXiQAS2m2N4J5MbbkBoN2NMIbdTxLCmHKbj1UBDUK8IDdS+kjhnPF5te49x6STepXdjOh28KZzJi6klf4Z/fkfUG20EC335H2dHyGCuA1w19LdzZq8apyWCeAPKOAjQb90s7L3OR3jfREQd62O9zJkbE/xCO0205msy9+TBULPkVDx4ddhfzzzvZVeGFgqyQX6lhor7rs0BUj4QVTvydYY/RVx4okJkchBZBo6 gyZIYhZ2 1P0G5dWDdthajC1UjXwBX12smQN63//M3Y9g4FLCV7pa1UJGjyJSpEJglTPUJPOHWS86jxZIuvBQKjl7njXpy1zgfueWHm/OEVo21rYAI3C8GHEK0Qd4PoWwCNFlPjFtzWbn1M4guMOOmvWi3QU/DQnKxkDGnuV+uMJ5HLYQpRkr12riZ5HTu9KWBTKFNXSFRK9mOhBLweSna8UYvSLEED56zg5S9rftH9tuwvpqotrStkb+Su5Hd9/ZRLW367IMqZVUneSoeLEWgnUJwnFFfCtgon/jXxTZ0cJ0BmCJPOV6Jnd8= 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.1 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 | 71 +++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 33 +++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index b1eeed508459..50ecd2bd7372 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -1388,6 +1388,77 @@ size_t cxl_get_feature(struct cxl_memdev_state *mds, } EXPORT_SYMBOL_NS_GPL(cxl_get_feature, CXL); +/* + * FEAT_DATA_MIN_PAYLOAD_SIZE - min extra number of bytes should be + * available in the mailbox for storing the actual feature data so that + * the feature data transfer would work as expected. + */ +#define FEAT_DATA_MIN_PAYLOAD_SIZE 10 +int cxl_set_feature(struct cxl_memdev_state *mds, + const uuid_t feat_uuid, u8 feat_version, + void *feat_data, size_t feat_data_size, + u8 feat_flag) +{ + struct cxl_memdev_set_feat_pi { + struct cxl_mbox_set_feat_hdr hdr; + u8 feat_data[]; + } __packed; + size_t data_in_size, data_sent_size = 0; + struct cxl_mbox_cmd mbox_cmd; + size_t hdr_size; + int rc = 0; + + struct cxl_memdev_set_feat_pi *pi __free(kfree) = + kmalloc(mds->payload_size, GFP_KERNEL); + pi->hdr.uuid = feat_uuid; + pi->hdr.version = feat_version; + feat_flag &= ~CXL_SET_FEAT_FLAG_DATA_TRANSFER_MASK; + hdr_size = sizeof(pi->hdr); + /* + * Check minimum mbox payload size is available for + * the feature data transfer. + */ + if (hdr_size + FEAT_DATA_MIN_PAYLOAD_SIZE > mds->payload_size) + return -ENOMEM; + + if ((hdr_size + feat_data_size) <= mds->payload_size) { + pi->hdr.flags = cpu_to_le32(feat_flag | + CXL_SET_FEAT_FLAG_FULL_DATA_TRANSFER); + data_in_size = feat_data_size; + } else { + pi->hdr.flags = cpu_to_le32(feat_flag | + CXL_SET_FEAT_FLAG_INITIATE_DATA_TRANSFER); + data_in_size = mds->payload_size - hdr_size; + } + + do { + pi->hdr.offset = cpu_to_le16(data_sent_size); + memcpy(pi->feat_data, feat_data + data_sent_size, data_in_size); + mbox_cmd = (struct cxl_mbox_cmd) { + .opcode = CXL_MBOX_OP_SET_FEATURE, + .size_in = hdr_size + data_in_size, + .payload_in = pi, + }; + rc = cxl_internal_send_cmd(mds, &mbox_cmd); + if (rc < 0) + return rc; + + data_sent_size += data_in_size; + if (data_sent_size >= feat_data_size) + return 0; + + if ((feat_data_size - data_sent_size) <= (mds->payload_size - hdr_size)) { + data_in_size = feat_data_size - data_sent_size; + pi->hdr.flags = cpu_to_le32(feat_flag | + CXL_SET_FEAT_FLAG_FINISH_DATA_TRANSFER); + } else { + pi->hdr.flags = cpu_to_le32(feat_flag | + CXL_SET_FEAT_FLAG_CONTINUE_DATA_TRANSFER); + } + } while (true); +} +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 25698a6fbe66..c3cb8e2736b5 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -532,6 +532,7 @@ enum cxl_opcode { CXL_MBOX_OP_GET_SUP_LOG_SUBLIST = 0x0405, 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, @@ -780,6 +781,34 @@ struct cxl_mbox_get_feat_in { u8 selection; } __packed; +/* + * Set Feature CXL 3.1 Spec 8.2.9.6.3 + */ + +/* + * Set Feature input payload + * CXL rev 3.1 section 8.2.9.6.3 Table 8-101 + */ +/* 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, + CXL_SET_FEAT_FLAG_INITIATE_DATA_TRANSFER, + CXL_SET_FEAT_FLAG_CONTINUE_DATA_TRANSFER, + CXL_SET_FEAT_FLAG_FINISH_DATA_TRANSFER, + CXL_SET_FEAT_FLAG_ABORT_DATA_TRANSFER, + CXL_SET_FEAT_FLAG_DATA_TRANSFER_MAX +}; +#define CXL_SET_FEAT_FLAG_DATA_SAVED_ACROSS_RESET BIT(3) + +struct cxl_mbox_set_feat_hdr { + 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; @@ -918,6 +947,10 @@ size_t cxl_get_feature(struct cxl_memdev_state *mds, const uuid_t feat_uuid, void *feat_out, size_t feat_out_size, enum cxl_get_feat_selection selection); +int cxl_set_feature(struct cxl_memdev_state *mds, + const uuid_t feat_uuid, u8 feat_version, + void *feat_data, size_t feat_data_size, + u8 feat_flag); 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 Tue Jul 16 15:03:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13734595 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 7022BC3DA49 for ; Tue, 16 Jul 2024 15:04:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD9DC6B0096; Tue, 16 Jul 2024 11:04:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B62F86B0098; Tue, 16 Jul 2024 11:04:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 967FF6B0099; Tue, 16 Jul 2024 11:04:44 -0400 (EDT) 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 6C93F6B0096 for ; Tue, 16 Jul 2024 11:04:44 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 285128069E for ; Tue, 16 Jul 2024 15:04:44 +0000 (UTC) X-FDA: 82345937688.29.FB84E8F Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf21.hostedemail.com (Postfix) with ESMTP id DB36F1C002A for ; Tue, 16 Jul 2024 15:04:41 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; spf=pass (imf21.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=1721142263; 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=BhkA8gvvIgbJ9EN1rR6few7fS+TJ53ZErIR5hkmJSH8=; b=XmH8Tg55K5OpUjiBSRwl7slMrNS5O7cPo+jysITK1fnw4OqMySMpJe4KS3jwPc1X7tbcS/ iGtnxIGrqV5Ne/nBqO9bcKVpShtQ9JqXFoD9pcv2S5V+by3ekJzuowgZR/t0bAsN/HAcPS Be55K2aZpr2Zdtt6ZJbDBZlEqPHji+Q= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; spf=pass (imf21.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=1721142263; a=rsa-sha256; cv=none; b=EMXq8c8rf9tMNU7nXIg4karX0WgQZYgVgyrFfaCpj82/oAYeIZXYfffA8JVU40tCs64s6L HCbEtjkdhUsE6zR1mB6s/JHzvAjy9w50zGQxBvMQJ/PmX0mXbfTu0R2Pg16UN6CajKCpFm ITsSwly9vgpYdz6uqBiMkexdwstEJzE= Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4WNj4W37Xzz6JB5G; Tue, 16 Jul 2024 23:03:23 +0800 (CST) Received: from lhrpeml500006.china.huawei.com (unknown [7.191.161.198]) by mail.maildlp.com (Postfix) with ESMTPS id 35F2D1400DB; Tue, 16 Jul 2024 23:04:39 +0800 (CST) Received: from P_UKIT01-A7bmah.china.huawei.com (10.48.159.153) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 16 Jul 2024 16:04:37 +0100 From: To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH v9 07/11] cxl/memscrub: Add CXL memory device patrol scrub control feature Date: Tue, 16 Jul 2024 16:03:31 +0100 Message-ID: <20240716150336.2042-8-shiju.jose@huawei.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20240716150336.2042-1-shiju.jose@huawei.com> References: <20240716150336.2042-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.48.159.153] X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) To lhrpeml500006.china.huawei.com (7.191.161.198) X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: DB36F1C002A X-Stat-Signature: knuyuowt81hou9obpfnuwwjwn1roexf3 X-HE-Tag: 1721142281-488109 X-HE-Meta: U2FsdGVkX1/Tae3ugMQj07jsHqdRKIPkHDBZMWZ55RK8gBc2rJuZGqPVeiU+qbtF3XQ2h/SeC2QE+TfE3KKgutprsj9Jzsp7ATQ0qEPnr4eyksXAFdlRFytKofwFfG1D9PlvBxBI0cnto5SfxEM4CtcfZbT8RmCgDUIE5rpQKh5T+ZZudXtkP3O4eVHqR/3A9aRktwDBncT93qd1vCNpOIDMpYIb3XG/d3Lk4GkEOPxlRSuJAeqt78Ij6WYY6U3A8WIPZEhQOvs/wQwgHPxDpeQiHwo+hV3vnWVAi+ggholNUBvEUfR1J7cNAw7o4ttl3POJTyZUCcbXRZnJKwtMXV1rWHy7PUX761k7R43WI8BwL/xYSjsOuHTAvOrjiPjEYjHyOOFdAK6CqKV8D3hbf0rcMMfq5T+Zgs2wS28VhfRhsE1q6qUUiT2hvpOF3xN1hT6P95BKjvRbdHeOKrC8NZ9Oa135qD+L24xtjwFZE6W3J5ng3e4wFkCHjNIi0XQaxZKNk0qTQ+7cKRpeh6Tj//PrkixDtTTTEQQqWapvuJpor+JJ5ZxlR7pGcugaqfck+DltMbJEQCBRnt2bm1DC9qIxo/oklCD4KT7SrD1wEiwUS2SfgskCt1wu7PsgEL/e6aAZDjbKTVfyvF+2jTmKcWr1AlribUgzHoT57aoF7ab/zwrbaZMxA2leVgt0BOsrHrKLRfd51FflAe/3JRfJlAbb7ThEMUxrpTIJ/5f7TZzkKiGILR3aCiatvAaSQ3hkZ7L2L1y31AZHoRJHRdl/PRuQCOResi6b61A4SWPs531qCW591/Q2cPCB3xEfSQPH98tHVOckTRR+cigS2mV+zg/8yBEE8dPfk+NouB+QKrWCGGZQGNRB/+upDKXKWNCw/OaLN7Q2nUEKM7AreN3zvMSPrMnXgBNftZeVNyyX4kSyzHUXi6IWy8i2vubp6doaofdvu3LC1TAJIEBBzOC J7Url/qE S80pWi2csiwwM3eEhBMVAH2cBBDG6rZYJ9jhIMOEwW0ZBqcyAD9rrfmnOfInrQl7s9cjWgifqjbckEt8E6aIxpV3nLcIlTeTVyNt7/e/UmUH6LSofhhyCH41jwWYfjfw34tZox7thm1RZcO+xcokBu336GdMAJ7giosqkpcJH3eP31NLgMcPUj0hBaNSboXffe7iSQgWeHZqxLdVtemd2nkjETg== 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. Allow specifying the number of hours within which the patrol scrub must be completed, subject to minimum and maximum limits reported by the device. Also allow disabling scrub allowing trade-off error rates against performance. Add support for CXL memory device based patrol scrub control. Register with EDAC RAS control feature driver, which gets the scrub attr descriptors from the EDAC scrub and expose sysfs scrub control attributes to the userspace. For example CXL device based scrub control for the CXL mem0 device is exposed in /sys/bus/edac/devices/cxl_mem0/scrub/ Also add support for region based CXL memory patrol scrub control. CXL memory region may be interleaved across one or more CXL memory devices. For example region based scrub control for CXL region1 is exposed in /sys/bus/edac/devices/cxl_region1/scrub/ Open Questions: Q1: CXL 3.1 spec defined patrol scrub control feature at CXL memory devices with supporting set scrub cycle and enable/disable scrub. but not based on HPA range. Thus presently scrub control for a region is implemented based on all associated CXL memory devices. What is the exact use case for the CXL region based scrub control? How the HPA range, which Dan asked for region based scrubbing is used? Does spec change is required for patrol scrub control feature with support for setting the HPA range? Q2: Both CXL device based and CXL region based scrub control would be enabled at the same time in a system? Co-developed-by: Jonathan Cameron Signed-off-by: Jonathan Cameron Signed-off-by: Shiju Jose --- Documentation/scrub/edac-scrub.rst | 70 +++++ drivers/cxl/Kconfig | 19 ++ drivers/cxl/core/Makefile | 1 + drivers/cxl/core/memscrub.c | 413 +++++++++++++++++++++++++++++ drivers/cxl/core/region.c | 6 + drivers/cxl/cxlmem.h | 8 + drivers/cxl/mem.c | 4 + 7 files changed, 521 insertions(+) create mode 100644 Documentation/scrub/edac-scrub.rst create mode 100644 drivers/cxl/core/memscrub.c diff --git a/Documentation/scrub/edac-scrub.rst b/Documentation/scrub/edac-scrub.rst new file mode 100644 index 000000000000..cf7d8b130204 --- /dev/null +++ b/Documentation/scrub/edac-scrub.rst @@ -0,0 +1,70 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=================== +EDAC Scrub control +=================== + +Copyright (c) 2024 HiSilicon Limited. + +:Author: Shiju Jose +:License: The GNU Free Documentation License, Version 1.2 + (dual licensed under the GPL v2) +:Original Reviewers: + +- Written for: 6.12 +- Updated for: + +Introduction +------------ +The edac scrub driver provides interfaces for controlling the +memory scrubbers in the system. The scrub device drivers in the +system register with the edac scrub. The driver exposes the +scrub controls to the user in the sysfs. + +The File System +--------------- + +The control attributes of the registered scrubbers could be +accessed in the /sys/bus/edac/devices//scrub/ + +sysfs +----- + +Sysfs files are documented in +`Documentation/ABI/testing/sysfs-edac-scrub-control`. + +Example +------- + +The usage takes the form shown in this example:: + +1. CXL memory device patrol scrubber +1.1 device based +root@localhost:~# cat /sys/bus/edac/devices/cxl_mem0/scrub/cycle_in_hours_range +0x1-0xff +root@localhost:~# cat /sys/bus/edac/devices/cxl_mem0/scrub/cycle_in_hours +0xc +root@localhost:~# echo 30 > /sys/bus/edac/devices/cxl_mem0/scrub/cycle_in_hours +root@localhost:~# cat /sys/bus/edac/devices/cxl_mem0/scrub/cycle_in_hours +0x1e +root@localhost:~# echo 1 > /sys/bus/edac/devices/cxl_mem0/scrub/enable_background +root@localhost:~# cat /sys/bus/edac/devices/cxl_mem0/scrub/enable_background +1 +root@localhost:~# echo 0 > /sys/bus/edac/devices/cxl_mem0/scrub/enable_background +root@localhost:~# cat /sys/bus/edac/devices/cxl_mem0/scrub/enable_background +0 + +1.2. region based +root@localhost:~# cat /sys/bus/edac/devices/cxl_region0/scrub/cycle_in_hours_range +0x1-0xff +root@localhost:~# cat /sys/bus/edac/devices/cxl_region0/scrub/cycle_in_hours +0xc +root@localhost:~# echo 30 > /sys/bus/edac/devices/cxl_region0/scrub/cycle_in_hours +root@localhost:~# cat /sys/bus/edac/devices/cxl_region0/scrub/cycle_in_hours +0x1e +root@localhost:~# echo 1 > /sys/bus/edac/devices/cxl_region0/scrub/enable_background +root@localhost:~# cat /sys/bus/edac/devices/cxl_region0/scrub/enable_background +1 +root@localhost:~# echo 0 > /sys/bus/edac/devices/cxl_region0/scrub/enable_background +root@localhost:~# cat /sys/bus/edac/devices/cxl_region0/scrub/enable_background +0 diff --git a/drivers/cxl/Kconfig b/drivers/cxl/Kconfig index 99b5c25be079..7da70685a2db 100644 --- a/drivers/cxl/Kconfig +++ b/drivers/cxl/Kconfig @@ -145,4 +145,23 @@ config CXL_REGION_INVALIDATION_TEST If unsure, or if this kernel is meant for production environments, say N. +config CXL_SCRUB + bool "CXL: Memory scrub feature" + depends on CXL_PCI + depends on CXL_MEM + depends on EDAC + help + The CXL memory scrub control is an optional feature allows host to + control the scrub configurations of CXL Type 3 devices, which + supports patrol scrubbing. + + Registers with the scrub subsystem to provide control attributes + of CXL memory device scrubber to the user. + Provides interface functions to support configuring the CXL memory + device patrol scrubber. + + Say 'y/n' to enable/disable control of memory scrub parameters for + CXL.mem devices. See section 8.2.9.9.11.1 of CXL 3.1 specification + for detailed description of CXL memory patrol scrub control feature. + endif diff --git a/drivers/cxl/core/Makefile b/drivers/cxl/core/Makefile index 9259bcc6773c..e0fc814c3983 100644 --- a/drivers/cxl/core/Makefile +++ b/drivers/cxl/core/Makefile @@ -16,3 +16,4 @@ cxl_core-y += pmu.o cxl_core-y += cdat.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..430f85b01f6c --- /dev/null +++ b/drivers/cxl/core/memscrub.c @@ -0,0 +1,413 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * CXL memory scrub driver. + * + * Copyright (c) 2024 HiSilicon Limited. + * + * - Provides functions to configure patrol scrub feature of the + * CXL memory devices. + * - Registers with the scrub subsystem driver to expose the sysfs attributes + * to the user for configuring the CXL memory patrol scrub feature. + */ + +#define pr_fmt(fmt) "CXL_MEM_SCRUB: " fmt + +#include +#include +#include +#include +#include + +#define CXL_DEV_NUM_RAS_FEATURES 2 + +/*ToDo: This reusable function will be moved to a common file */ +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_supp_feat_entry *feat_entry; + struct cxl_dev_state *cxlds = cxlmd->cxlds; + struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds); + int feat_index, feats_out_size; + int nentries, count; + int ret; + + feat_index = 0; + feats_out_size = sizeof(struct cxl_mbox_get_supp_feats_out) + + sizeof(struct cxl_mbox_supp_feat_entry); + struct cxl_mbox_get_supp_feats_out *feats_out __free(kfree) = + kmalloc(feats_out_size, GFP_KERNEL); + if (!feats_out) + return -ENOMEM; + + while (true) { + memset(feats_out, 0, feats_out_size); + ret = cxl_get_supported_features(mds, feats_out_size, + feat_index, feats_out); + if (ret) + return ret; + + nentries = feats_out->nr_entries; + if (!nentries) + return -EOPNOTSUPP; + + /* Check CXL memdev supports the feature */ + feat_entry = 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; + } +} + +#define CXL_SCRUB_NAME_LEN 128 + +/* 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 { + u16 get_feat_size; + u16 set_feat_size; + struct cxl_memdev *cxlmd; + struct cxl_region *cxlr; +}; + +/** + * struct cxl_memdev_ps_params - CXL memory patrol scrub parameter data structure. + * @enable: [IN & OUT] enable(1)/disable(0) patrol scrub. + * @scrub_cycle_changeable: [OUT] scrub cycle attribute of patrol scrub is changeable. + * @scrub_cycle_hrs: [IN] Requested patrol scrub cycle in hours. + * [OUT] Current patrol scrub cycle in hours. + * @min_scrub_cycle_hrs:[OUT] minimum patrol scrub cycle in hours supported. + */ +struct cxl_memdev_ps_params { + bool enable; + bool scrub_cycle_changeable; + u16 scrub_cycle_hrs; + u16 min_scrub_cycle_hrs; +}; + +enum cxl_scrub_param { + cxl_ps_param_enable, + cxl_ps_param_scrub_cycle, +}; + +#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_rd_attrs { + u8 scrub_cycle_cap; + __le16 scrub_cycle_hrs; + u8 scrub_flags; +} __packed; + +struct cxl_memdev_ps_wr_attrs { + u8 scrub_cycle_hrs; + u8 scrub_flags; +} __packed; + +static int cxl_mem_ps_get_attrs(struct cxl_memdev_state *mds, + struct cxl_memdev_ps_params *params) +{ + size_t rd_data_size = sizeof(struct cxl_memdev_ps_rd_attrs); + size_t data_size; + struct cxl_memdev_ps_rd_attrs *rd_attrs __free(kfree) = + kmalloc(rd_data_size, GFP_KERNEL); + if (!rd_attrs) + return -ENOMEM; + + data_size = cxl_get_feature(mds, cxl_patrol_scrub_uuid, rd_attrs, + rd_data_size, CXL_GET_FEAT_SEL_CURRENT_VALUE); + if (!data_size) + return -EIO; + + params->scrub_cycle_changeable = FIELD_GET(CXL_MEMDEV_PS_SCRUB_CYCLE_CHANGE_CAP_MASK, + rd_attrs->scrub_cycle_cap); + params->enable = FIELD_GET(CXL_MEMDEV_PS_FLAG_ENABLED_MASK, + rd_attrs->scrub_flags); + params->scrub_cycle_hrs = FIELD_GET(CXL_MEMDEV_PS_CUR_SCRUB_CYCLE_MASK, + rd_attrs->scrub_cycle_hrs); + params->min_scrub_cycle_hrs = FIELD_GET(CXL_MEMDEV_PS_MIN_SCRUB_CYCLE_MASK, + rd_attrs->scrub_cycle_hrs); + + return 0; +} + +static int cxl_ps_get_attrs(struct device *dev, void *drv_data, + struct cxl_memdev_ps_params *params) +{ + struct cxl_patrol_scrub_context *cxl_ps_ctx = drv_data; + struct cxl_memdev *cxlmd; + struct cxl_dev_state *cxlds; + struct cxl_memdev_state *mds; + u16 min_scrub_cycle = 0; + int i, ret; + + if (cxl_ps_ctx->cxlr) { + struct cxl_region *cxlr = cxl_ps_ctx->cxlr; + struct cxl_region_params *p = &cxlr->params; + + for (i = p->interleave_ways - 1; i >= 0; i--) { + struct cxl_endpoint_decoder *cxled = p->targets[i]; + + cxlmd = cxled_to_memdev(cxled); + cxlds = cxlmd->cxlds; + mds = to_cxl_memdev_state(cxlds); + ret = cxl_mem_ps_get_attrs(mds, params); + if (ret) + return ret; + + if (params->min_scrub_cycle_hrs > min_scrub_cycle) + min_scrub_cycle = params->min_scrub_cycle_hrs; + } + params->min_scrub_cycle_hrs = min_scrub_cycle; + return 0; + } + cxlmd = cxl_ps_ctx->cxlmd; + cxlds = cxlmd->cxlds; + mds = to_cxl_memdev_state(cxlds); + + return cxl_mem_ps_get_attrs(mds, params); +} + +static int cxl_mem_ps_set_attrs(struct device *dev, struct cxl_memdev_state *mds, + struct cxl_memdev_ps_params *params, + enum cxl_scrub_param param_type) +{ + struct cxl_memdev_ps_wr_attrs wr_attrs; + struct cxl_memdev_ps_params rd_params; + int ret; + + ret = cxl_mem_ps_get_attrs(mds, &rd_params); + if (ret) { + dev_err(dev, "Get cxlmemdev patrol scrub params failed ret=%d\n", + ret); + return ret; + } + + switch (param_type) { + case cxl_ps_param_enable: + wr_attrs.scrub_flags = FIELD_PREP(CXL_MEMDEV_PS_FLAG_ENABLED_MASK, + params->enable); + wr_attrs.scrub_cycle_hrs = FIELD_PREP(CXL_MEMDEV_PS_CUR_SCRUB_CYCLE_MASK, + rd_params.scrub_cycle_hrs); + break; + case cxl_ps_param_scrub_cycle: + if (params->scrub_cycle_hrs < rd_params.min_scrub_cycle_hrs) { + dev_err(dev, "Invalid CXL patrol scrub cycle(%d) to set\n", + params->scrub_cycle_hrs); + dev_err(dev, "Minimum supported CXL patrol scrub cycle in hour %d\n", + params->min_scrub_cycle_hrs); + return -EINVAL; + } + wr_attrs.scrub_cycle_hrs = FIELD_PREP(CXL_MEMDEV_PS_CUR_SCRUB_CYCLE_MASK, + params->scrub_cycle_hrs); + wr_attrs.scrub_flags = FIELD_PREP(CXL_MEMDEV_PS_FLAG_ENABLED_MASK, + rd_params.enable); + break; + } + + ret = cxl_set_feature(mds, cxl_patrol_scrub_uuid, CXL_MEMDEV_PS_SET_FEAT_VERSION, + &wr_attrs, sizeof(wr_attrs), + CXL_SET_FEAT_FLAG_DATA_SAVED_ACROSS_RESET); + if (ret) { + dev_err(dev, "CXL patrol scrub set feature failed ret=%d\n", ret); + return ret; + } + + return 0; +} + +static int cxl_ps_set_attrs(struct device *dev, void *drv_data, + struct cxl_memdev_ps_params *params, + enum cxl_scrub_param param_type) +{ + struct cxl_patrol_scrub_context *cxl_ps_ctx = drv_data; + struct cxl_memdev *cxlmd; + struct cxl_dev_state *cxlds; + struct cxl_memdev_state *mds; + int ret, i; + + if (cxl_ps_ctx->cxlr) { + struct cxl_region *cxlr = cxl_ps_ctx->cxlr; + struct cxl_region_params *p = &cxlr->params; + + for (i = p->interleave_ways - 1; i >= 0; i--) { + struct cxl_endpoint_decoder *cxled = p->targets[i]; + + cxlmd = cxled_to_memdev(cxled); + cxlds = cxlmd->cxlds; + mds = to_cxl_memdev_state(cxlds); + ret = cxl_mem_ps_set_attrs(dev, mds, params, param_type); + if (ret) + return ret; + } + } else { + cxlmd = cxl_ps_ctx->cxlmd; + cxlds = cxlmd->cxlds; + mds = to_cxl_memdev_state(cxlds); + + return cxl_mem_ps_set_attrs(dev, mds, params, param_type); + } + + return 0; +} + +static int cxl_patrol_scrub_get_enabled_bg(struct device *dev, void *drv_data, bool *enabled) +{ + struct cxl_memdev_ps_params params; + int ret; + + ret = cxl_ps_get_attrs(dev, drv_data, ¶ms); + if (ret) + return ret; + + *enabled = params.enable; + + return 0; +} + +static int cxl_patrol_scrub_set_enabled_bg(struct device *dev, void *drv_data, bool enable) +{ + struct cxl_memdev_ps_params params = { + .enable = enable, + }; + + return cxl_ps_set_attrs(dev, drv_data, ¶ms, cxl_ps_param_enable); +} + +static int cxl_patrol_scrub_get_name(struct device *dev, void *drv_data, char *name) +{ + struct cxl_patrol_scrub_context *cxl_ps_ctx = drv_data; + struct cxl_memdev *cxlmd = cxl_ps_ctx->cxlmd; + + if (cxl_ps_ctx->cxlr) { + struct cxl_region *cxlr = cxl_ps_ctx->cxlr; + + return sysfs_emit(name, "cxl_region%d_patrol_scrub\n", cxlr->id); + } + + return sysfs_emit(name, "cxl_%s_patrol_scrub\n", dev_name(&cxlmd->dev)); +} + +static int cxl_patrol_scrub_write_scrub_cycle_hrs(struct device *dev, void *drv_data, + u64 scrub_cycle_hrs) +{ + struct cxl_memdev_ps_params params = { + .scrub_cycle_hrs = scrub_cycle_hrs, + }; + + return cxl_ps_set_attrs(dev, drv_data, ¶ms, cxl_ps_param_scrub_cycle); +} + +static int cxl_patrol_scrub_read_scrub_cycle_hrs(struct device *dev, void *drv_data, + u64 *scrub_cycle_hrs) +{ + struct cxl_memdev_ps_params params; + int ret; + + ret = cxl_ps_get_attrs(dev, drv_data, ¶ms); + if (ret) + return ret; + + *scrub_cycle_hrs = params.scrub_cycle_hrs; + + return 0; +} + +static int cxl_patrol_scrub_read_scrub_cycle_hrs_range(struct device *dev, void *drv_data, + u64 *min, u64 *max) +{ + struct cxl_memdev_ps_params params; + int ret; + + ret = cxl_ps_get_attrs(dev, drv_data, ¶ms); + if (ret) + return ret; + *min = params.min_scrub_cycle_hrs; + *max = U8_MAX; /* Max set by register size */ + + return 0; +} + +static const struct edac_scrub_ops cxl_ps_scrub_ops = { + .get_enabled_bg = cxl_patrol_scrub_get_enabled_bg, + .set_enabled_bg = cxl_patrol_scrub_set_enabled_bg, + .get_name = cxl_patrol_scrub_get_name, + .cycle_in_hours_read = cxl_patrol_scrub_read_scrub_cycle_hrs, + .cycle_in_hours_write = cxl_patrol_scrub_write_scrub_cycle_hrs, + .cycle_in_hours_range = cxl_patrol_scrub_read_scrub_cycle_hrs_range, +}; + +int cxl_mem_ras_features_init(struct cxl_memdev *cxlmd, struct cxl_region *cxlr) +{ + struct edac_ras_feature ras_features[CXL_DEV_NUM_RAS_FEATURES]; + struct cxl_patrol_scrub_context *cxl_ps_ctx; + struct cxl_mbox_supp_feat_entry feat_entry; + char cxl_dev_name[CXL_SCRUB_NAME_LEN]; + int rc, i, num_ras_features = 0; + + if (cxlr) { + struct cxl_region_params *p = &cxlr->params; + + for (i = p->interleave_ways - 1; i >= 0; i--) { + struct cxl_endpoint_decoder *cxled = p->targets[i]; + + cxlmd = cxled_to_memdev(cxled); + memset(&feat_entry, 0, sizeof(feat_entry)); + rc = cxl_mem_get_supported_feature_entry(cxlmd, &cxl_patrol_scrub_uuid, + &feat_entry); + if (rc < 0) + return rc; + if (!(feat_entry.attr_flags & CXL_FEAT_ENTRY_FLAG_CHANGABLE)) + return -EOPNOTSUPP; + } + } else { + rc = cxl_mem_get_supported_feature_entry(cxlmd, &cxl_patrol_scrub_uuid, + &feat_entry); + if (rc < 0) + return rc; + + if (!(feat_entry.attr_flags & CXL_FEAT_ENTRY_FLAG_CHANGABLE)) + return -EOPNOTSUPP; + } + + cxl_ps_ctx = devm_kzalloc(&cxlmd->dev, sizeof(*cxl_ps_ctx), GFP_KERNEL); + if (!cxl_ps_ctx) + return -ENOMEM; + + *cxl_ps_ctx = (struct cxl_patrol_scrub_context) { + .get_feat_size = feat_entry.get_size, + .set_feat_size = feat_entry.set_size, + }; + if (cxlr) { + snprintf(cxl_dev_name, sizeof(cxl_dev_name), + "cxl_region%d", cxlr->id); + cxl_ps_ctx->cxlr = cxlr; + } else { + snprintf(cxl_dev_name, sizeof(cxl_dev_name), + "%s_%s", "cxl", dev_name(&cxlmd->dev)); + cxl_ps_ctx->cxlmd = cxlmd; + } + + ras_features[num_ras_features].feat = ras_feat_scrub; + ras_features[num_ras_features].scrub_ops = &cxl_ps_scrub_ops; + ras_features[num_ras_features].scrub_ctx = cxl_ps_ctx; + num_ras_features++; + + return edac_ras_dev_register(&cxlmd->dev, cxl_dev_name, NULL, + num_ras_features, ras_features); +} +EXPORT_SYMBOL_NS_GPL(cxl_mem_ras_features_init, CXL); diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 3c2b6144be23..14db9d301747 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3304,6 +3304,12 @@ static int cxl_region_probe(struct device *dev) p->res->start, p->res->end, cxlr, is_system_ram) > 0) return 0; + + rc = cxl_mem_ras_features_init(NULL, cxlr); + if (rc) + dev_warn(&cxlr->dev, "CXL ras features init for region_id=%d failed\n", + cxlr->id); + return devm_cxl_add_dax_region(cxlr); default: dev_dbg(&cxlr->dev, "unsupported region mode: %d\n", diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index c3cb8e2736b5..9a0eb41e5997 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -958,6 +958,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_ras_features_init(struct cxl_memdev *cxlmd, struct cxl_region *cxlr); +#else +static inline int cxl_mem_ras_features_init(struct cxl_memdev *cxlmd, struct cxl_region *cxlr) +{ return 0; } +#endif + #ifdef CONFIG_CXL_SUSPEND void cxl_mem_active_inc(void); void cxl_mem_active_dec(void); diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c index 0c79d9ce877c..7c8360e2e09b 100644 --- a/drivers/cxl/mem.c +++ b/drivers/cxl/mem.c @@ -117,6 +117,10 @@ static int cxl_mem_probe(struct device *dev) if (!cxlds->media_ready) return -EBUSY; + rc = cxl_mem_ras_features_init(cxlmd, NULL); + if (rc) + dev_warn(&cxlmd->dev, "CXL ras features init failed\n"); + /* * Someone is trying to reattach this device after it lost its port * connection (an endpoint port previously registered by this memdev was From patchwork Tue Jul 16 15:03:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13734596 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 DA97CC3DA61 for ; Tue, 16 Jul 2024 15:04:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 06A196B009A; Tue, 16 Jul 2024 11:04:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F37C46B009B; Tue, 16 Jul 2024 11:04:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D39656B009C; Tue, 16 Jul 2024 11:04:46 -0400 (EDT) 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 A99256B009A for ; Tue, 16 Jul 2024 11:04:46 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 56AF2A160D for ; Tue, 16 Jul 2024 15:04:46 +0000 (UTC) X-FDA: 82345937772.20.0916ED2 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf24.hostedemail.com (Postfix) with ESMTP id 0CDE918000F for ; Tue, 16 Jul 2024 15:04:43 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.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=1721142246; 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=0Nra/Yiqtv/Dv6/7o4xOq+t+i2AiIEWEPacyQAW3+gw=; b=YxeNVmobdc+CIm8v9AGvZBS2LIuJNk6nTrvKK7i/cN/M9Zz/mv4U3F7MHZchfa6U93CTao PLgdjWoT/tajRcPMoV3QjkjgQGjS7k56MpwRxcQjpN/s1OuD6DqLtmjevjDx9wvec5Zd9w xXFG2b0qKFRvZhx+6azzpUk8EKwVlUs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721142246; a=rsa-sha256; cv=none; b=OLgTj4UTG2OBrIKwKgHRdrQ/fAiAS18FD72XmuO65D5ED171SGNFXvuTIicAHulmXzdD8P A4gc4MyJfproFfpe5/4d8gsDci/BOiCh9WlJpdxDNqq/O52tp7qx8a8yIRSL5tzGCv+eFg QrJFzxC3t+TH5Gi7pk9yFkzu004kneI= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4WNj4Y5T9Nz6JB2K; Tue, 16 Jul 2024 23:03:25 +0800 (CST) Received: from lhrpeml500006.china.huawei.com (unknown [7.191.161.198]) by mail.maildlp.com (Postfix) with ESMTPS id 901A41400DB; Tue, 16 Jul 2024 23:04:41 +0800 (CST) Received: from P_UKIT01-A7bmah.china.huawei.com (10.48.159.153) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 16 Jul 2024 16:04:39 +0100 From: To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH v9 08/11] cxl/memscrub: Add CXL memory device ECS control feature Date: Tue, 16 Jul 2024 16:03:32 +0100 Message-ID: <20240716150336.2042-9-shiju.jose@huawei.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20240716150336.2042-1-shiju.jose@huawei.com> References: <20240716150336.2042-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.48.159.153] X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) To lhrpeml500006.china.huawei.com (7.191.161.198) X-Rspamd-Queue-Id: 0CDE918000F X-Stat-Signature: 8bgm6ym5k78egg8hp9pp584s36yyr6zb X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1721142283-91403 X-HE-Meta: U2FsdGVkX1+3Q0ACTziTnm3bqsjXPdBIfumhq5VqsNqD4+/jfysPiEi/Jsiu4+WN8q/uwrmum9e4cJaaPBO0+2OaxKTuOZtbw0dc+Xn5KEapa/DzgNhbwU9HvV8tQGXltzQeNNZYPsXrKbPLCR6PWuTrFHpeVWiML9I35IqNUytkHm9MIFTfegkdbgUmIw0uHyahTn27tx3AUpbTaB7gZn7vybLcaLeLTAgmrzgMyERZkNAWp7bDIUUIcPa/pRHzwwwE7QTuuONYWzzspc+qcTbUgw/5isYe3A//EQzKCJtxNXM6kpSc6KzvDJeVAT2ADmzvpHqKTU0g/vBDHsRcmyXQURyyhiYqjUwzOulsqMd7u45bzDUBMC+wSzWOgr7y0JUbfo/5xcdnRyCfLzC4KspwEudjlCK6s3yV2FKwQmKbeHhCxgMHssfGsxY7n4mdumz8oHHxWGl6sNHTbdBgcDNc1T8gAIViHhNJCiMHX+T8vsF+QvP6h7/gCfw6koTE344uxjVdiEK43iNLWO1cbLVYm5lKH4kt9daLF8J1Un+faImFej3PoVAe6enUwiu87Nxmjsv8BBFxHvNzHZ19St2aKU8bdVf28xopPjCoZSleMGCi2dtcTN3VQEcKYQn/+GEiCl4AgrxL6HG/7vl8hiOQ6kOy0X6Vf5Xp02+e2h9HSuHmpawA2EJat6V1EOK2s8ld+nAPoks7xI5bLfWGs6n5bEU2vch96ahSb0PFHXcKWSvUEs0oZjtS6ga6szzVMxhUg7QjZdkZ5n0REToTURYB3eW7dwmffCI2Fn/xQNx/v/nXBSKc1SUXoGy7LSs7w6Vq/n1zgMAels+Tx3qXm8M1522hGDMLbH3l2EylyQ0WXl/sfbOHR65VlwJPakpDoeC4PGZzgyPJ8tMi43gVkGNpVp0NxzKzQjyLDeqbsngwzkv1kkbiln0NoYICl6zvN6ABsDzvTmR85/Dso6C zBT84hXH cmuJyNJjyzEwkFVMWGur+5wjPxgAB4cOEj9qEfrfH0K05yZ+S5dzWJobfDO4F9Y3UdfdJrJzLNlyV0kvh7pKmFWZkPtyna19Be3ZxdYBew+MLkSsQGMi93oHvusWwM+WxbpJp+cRDvJyqwdsVGMZJmYvsvBchhrMs9Os9v9F+q2GbYpKqvQ5rxFy4Bd0rms/gZ2UqTxZNKQ8Wvzh76u0K8WkwdQ== 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 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. Register with EDAC RAS control feature driver, which gets the ECS attr descriptors from the EDAC ECS and expose sysfs ECS control attributes to the userspace. For example ECS control for the memory media FRU 0 in CXL mem0 device is in /sys/bus/edac/devices/cxl_mem0/ecs_fru0/ Note: The documentation can be added if necessary. Signed-off-by: Shiju Jose --- drivers/cxl/core/memscrub.c | 429 ++++++++++++++++++++++++++++++++++++ 1 file changed, 429 insertions(+) diff --git a/drivers/cxl/core/memscrub.c b/drivers/cxl/core/memscrub.c index 430f85b01f6c..9be230ea989a 100644 --- a/drivers/cxl/core/memscrub.c +++ b/drivers/cxl/core/memscrub.c @@ -351,13 +351,411 @@ static const struct edac_scrub_ops cxl_ps_scrub_ops = { .cycle_in_hours_range = cxl_patrol_scrub_read_scrub_cycle_hrs_range, }; +/* 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 { + u16 num_media_frus; + u16 get_feat_size; + u16 set_feat_size; + struct cxl_memdev *cxlmd; +}; + +/** + * struct cxl_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_ecs_params { + u8 log_entry_type; + u16 threshold; + u8 mode; + bool reset_counter; +}; + +enum { + CXL_ECS_PARAM_LOG_ENTRY_TYPE, + CXL_ECS_PARAM_THRESHOLD, + CXL_ECS_PARAM_MODE, + CXL_ECS_PARAM_RESET_COUNTER, +}; + +#define CXL_ECS_LOG_ENTRY_TYPE_MASK GENMASK(1, 0) +#define CXL_ECS_REALTIME_REPORT_CAP_MASK BIT(0) +#define CXL_ECS_THRESHOLD_COUNT_MASK GENMASK(2, 0) +#define CXL_ECS_MODE_MASK BIT(3) +#define CXL_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_ecs_rd_attrs { + u8 ecs_log_cap; + u8 ecs_cap; + __le16 ecs_config; + u8 ecs_flags; +} __packed; + +struct cxl_ecs_wr_attrs { + u8 ecs_log_cap; + __le16 ecs_config; +} __packed; + +/* CXL DDR5 ECS control functions */ +static int cxl_mem_ecs_get_attrs(struct device *dev, void *drv_data, int fru_id, + struct cxl_ecs_params *params) +{ + struct cxl_ecs_context *cxl_ecs_ctx = drv_data; + struct cxl_memdev *cxlmd = cxl_ecs_ctx->cxlmd; + struct cxl_dev_state *cxlds = cxlmd->cxlds; + struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds); + size_t rd_data_size; + u8 threshold_index; + size_t data_size; + + rd_data_size = cxl_ecs_ctx->get_feat_size; + + struct cxl_ecs_rd_attrs *rd_attrs __free(kfree) = + kmalloc(rd_data_size, GFP_KERNEL); + if (!rd_attrs) + return -ENOMEM; + + params->log_entry_type = 0; + params->threshold = 0; + params->mode = 0; + data_size = cxl_get_feature(mds, cxl_ecs_uuid, rd_attrs, + rd_data_size, CXL_GET_FEAT_SEL_CURRENT_VALUE); + if (!data_size) + return -EIO; + + params->log_entry_type = FIELD_GET(CXL_ECS_LOG_ENTRY_TYPE_MASK, + rd_attrs[fru_id].ecs_log_cap); + threshold_index = FIELD_GET(CXL_ECS_THRESHOLD_COUNT_MASK, + rd_attrs[fru_id].ecs_config); + params->threshold = ecs_supp_threshold[threshold_index]; + params->mode = FIELD_GET(CXL_ECS_MODE_MASK, + rd_attrs[fru_id].ecs_config); + return 0; +} + +static int cxl_mem_ecs_set_attrs(struct device *dev, void *drv_data, int fru_id, + struct cxl_ecs_params *params, u8 param_type) +{ + struct cxl_ecs_context *cxl_ecs_ctx = drv_data; + struct cxl_memdev *cxlmd = cxl_ecs_ctx->cxlmd; + struct cxl_dev_state *cxlds = cxlmd->cxlds; + struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds); + size_t rd_data_size, wr_data_size; + u16 num_media_frus, count; + size_t data_size; + int ret; + + num_media_frus = cxl_ecs_ctx->num_media_frus; + rd_data_size = cxl_ecs_ctx->get_feat_size; + wr_data_size = cxl_ecs_ctx->set_feat_size; + struct cxl_ecs_rd_attrs *rd_attrs __free(kfree) = + kmalloc(rd_data_size, GFP_KERNEL); + if (!rd_attrs) + return -ENOMEM; + + data_size = cxl_get_feature(mds, cxl_ecs_uuid, rd_attrs, + rd_data_size, CXL_GET_FEAT_SEL_CURRENT_VALUE); + if (!data_size) + return -EIO; + struct cxl_ecs_wr_attrs *wr_attrs __free(kfree) = + kmalloc(wr_data_size, GFP_KERNEL); + if (!wr_attrs) + return -ENOMEM; + + /* Fill writable attributes from the current attributes read for all the media FRUs */ + for (count = 0; count < num_media_frus; count++) { + wr_attrs[count].ecs_log_cap = rd_attrs[count].ecs_log_cap; + wr_attrs[count].ecs_config = rd_attrs[count].ecs_config; + } + + /* Fill attribute to be set for the media FRU */ + switch (param_type) { + case CXL_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, + "Invalid CXL ECS scrub log entry type(%d) to set\n", + params->log_entry_type); + dev_err(dev, + "Log Entry Type 0: per DRAM 1: per Memory Media FRU\n"); + return -EINVAL; + } + wr_attrs[fru_id].ecs_log_cap = FIELD_PREP(CXL_ECS_LOG_ENTRY_TYPE_MASK, + params->log_entry_type); + break; + case CXL_ECS_PARAM_THRESHOLD: + wr_attrs[fru_id].ecs_config &= ~CXL_ECS_THRESHOLD_COUNT_MASK; + switch (params->threshold) { + case 256: + wr_attrs[fru_id].ecs_config |= FIELD_PREP( + CXL_ECS_THRESHOLD_COUNT_MASK, + ECS_THRESHOLD_256); + break; + case 1024: + wr_attrs[fru_id].ecs_config |= FIELD_PREP( + CXL_ECS_THRESHOLD_COUNT_MASK, + ECS_THRESHOLD_1024); + break; + case 4096: + wr_attrs[fru_id].ecs_config |= FIELD_PREP( + CXL_ECS_THRESHOLD_COUNT_MASK, + ECS_THRESHOLD_4096); + break; + default: + dev_err(dev, + "Invalid CXL ECS scrub threshold count(%d) to set\n", + params->threshold); + dev_err(dev, + "Supported scrub threshold count: 256,1024,4096\n"); + return -EINVAL; + } + break; + case CXL_ECS_PARAM_MODE: + if (params->mode != ECS_MODE_COUNTS_ROWS && + params->mode != ECS_MODE_COUNTS_CODEWORDS) { + dev_err(dev, + "Invalid CXL ECS scrub mode(%d) to set\n", + params->mode); + dev_err(dev, + "Mode 0: ECS counts rows with errors" + " 1: ECS counts codewords with errors\n"); + return -EINVAL; + } + wr_attrs[fru_id].ecs_config &= ~CXL_ECS_MODE_MASK; + wr_attrs[fru_id].ecs_config |= FIELD_PREP(CXL_ECS_MODE_MASK, + params->mode); + break; + case CXL_ECS_PARAM_RESET_COUNTER: + wr_attrs[fru_id].ecs_config &= ~CXL_ECS_RESET_COUNTER_MASK; + wr_attrs[fru_id].ecs_config |= FIELD_PREP(CXL_ECS_RESET_COUNTER_MASK, + params->reset_counter); + break; + default: + dev_err(dev, "Invalid CXL ECS parameter to set\n"); + return -EINVAL; + } + + ret = cxl_set_feature(mds, cxl_ecs_uuid, CXL_MEMDEV_ECS_SET_FEAT_VERSION, + wr_attrs, wr_data_size, + CXL_SET_FEAT_FLAG_DATA_SAVED_ACROSS_RESET); + if (ret) { + dev_err(dev, "CXL ECS set feature failed ret=%d\n", ret); + return ret; + } + + return 0; +} + +static int cxl_ecs_get_log_entry_type(struct device *dev, void *drv_data, int fru_id, u64 *val) +{ + struct cxl_ecs_params params; + int ret; + + ret = cxl_mem_ecs_get_attrs(dev, drv_data, fru_id, ¶ms); + if (ret) + return ret; + + *val = params.log_entry_type; + + return 0; +} + +static int cxl_ecs_set_log_entry_type(struct device *dev, void *drv_data, int fru_id, u64 val) +{ + struct cxl_ecs_params params = { + .log_entry_type = val, + }; + + return cxl_mem_ecs_set_attrs(dev, drv_data, fru_id, ¶ms, CXL_ECS_PARAM_LOG_ENTRY_TYPE); +} + +static int cxl_ecs_get_log_entry_type_per_dram(struct device *dev, void *drv_data, + int fru_id, u64 *val) +{ + struct cxl_ecs_params params; + int ret; + + ret = cxl_mem_ecs_get_attrs(dev, drv_data, fru_id, ¶ms); + if (ret) + return ret; + + if (params.log_entry_type == ECS_LOG_ENTRY_TYPE_DRAM) + *val = 1; + else + *val = 0; + + return 0; +} + +static int cxl_ecs_get_log_entry_type_per_memory_media(struct device *dev, void *drv_data, + int fru_id, u64 *val) +{ + struct cxl_ecs_params params; + int ret; + + ret = cxl_mem_ecs_get_attrs(dev, drv_data, fru_id, ¶ms); + if (ret) + return ret; + + if (params.log_entry_type == ECS_LOG_ENTRY_TYPE_MEM_MEDIA_FRU) + *val = 1; + else + *val = 0; + + return 0; +} + +static int cxl_ecs_get_mode(struct device *dev, void *drv_data, int fru_id, u64 *val) +{ + struct cxl_ecs_params params; + int ret; + + ret = cxl_mem_ecs_get_attrs(dev, drv_data, fru_id, ¶ms); + if (ret) + return ret; + + *val = params.mode; + + return 0; +} + +static int cxl_ecs_set_mode(struct device *dev, void *drv_data, int fru_id, u64 val) +{ + struct cxl_ecs_params params = { + .mode = val, + }; + + return cxl_mem_ecs_set_attrs(dev, drv_data, fru_id, ¶ms, CXL_ECS_PARAM_MODE); +} + +static int cxl_ecs_get_mode_counts_rows(struct device *dev, void *drv_data, int fru_id, u64 *val) +{ + struct cxl_ecs_params params; + int ret; + + ret = cxl_mem_ecs_get_attrs(dev, drv_data, fru_id, ¶ms); + if (ret) + return ret; + + if (params.mode == ECS_MODE_COUNTS_ROWS) + *val = 1; + else + *val = 0; + + return 0; +} + +static int cxl_ecs_get_mode_counts_codewords(struct device *dev, void *drv_data, + int fru_id, u64 *val) +{ + struct cxl_ecs_params params; + int ret; + + ret = cxl_mem_ecs_get_attrs(dev, drv_data, fru_id, ¶ms); + if (ret) + return ret; + + if (params.mode == ECS_MODE_COUNTS_CODEWORDS) + *val = 1; + else + *val = 0; + + return 0; +} + +static int cxl_ecs_reset(struct device *dev, void *drv_data, int fru_id, u64 val) +{ + struct cxl_ecs_params params = { + .reset_counter = val, + }; + + return cxl_mem_ecs_set_attrs(dev, drv_data, fru_id, ¶ms, CXL_ECS_PARAM_RESET_COUNTER); +} + +static int cxl_ecs_get_threshold(struct device *dev, void *drv_data, int fru_id, u64 *val) +{ + struct cxl_ecs_params params; + int ret; + + ret = cxl_mem_ecs_get_attrs(dev, drv_data, fru_id, ¶ms); + if (ret) + return ret; + + *val = params.threshold; + + return 0; +} + +static int cxl_ecs_set_threshold(struct device *dev, void *drv_data, int fru_id, u64 val) +{ + struct cxl_ecs_params params = { + .threshold = val, + }; + + return cxl_mem_ecs_set_attrs(dev, drv_data, fru_id, ¶ms, CXL_ECS_PARAM_THRESHOLD); +} + +static int cxl_ecs_get_name(struct device *dev, void *drv_data, int fru_id, char *name) +{ + struct cxl_ecs_context *cxl_ecs_ctx = drv_data; + struct cxl_memdev *cxlmd = cxl_ecs_ctx->cxlmd; + + return sysfs_emit(name, "cxl_%s_ecs_fru%d\n", dev_name(&cxlmd->dev), fru_id); +} + +static const struct edac_ecs_ops cxl_ecs_ops = { + .get_log_entry_type = cxl_ecs_get_log_entry_type, + .set_log_entry_type = cxl_ecs_set_log_entry_type, + .get_log_entry_type_per_dram = cxl_ecs_get_log_entry_type_per_dram, + .get_log_entry_type_per_memory_media = cxl_ecs_get_log_entry_type_per_memory_media, + .get_mode = cxl_ecs_get_mode, + .set_mode = cxl_ecs_set_mode, + .get_mode_counts_codewords = cxl_ecs_get_mode_counts_codewords, + .get_mode_counts_rows = cxl_ecs_get_mode_counts_rows, + .reset = cxl_ecs_reset, + .get_threshold = cxl_ecs_get_threshold, + .set_threshold = cxl_ecs_set_threshold, + .get_name = cxl_ecs_get_name, +}; + int cxl_mem_ras_features_init(struct cxl_memdev *cxlmd, struct cxl_region *cxlr) { struct edac_ras_feature ras_features[CXL_DEV_NUM_RAS_FEATURES]; struct cxl_patrol_scrub_context *cxl_ps_ctx; struct cxl_mbox_supp_feat_entry feat_entry; char cxl_dev_name[CXL_SCRUB_NAME_LEN]; + struct cxl_ecs_context *cxl_ecs_ctx; int rc, i, num_ras_features = 0; + int num_media_frus; if (cxlr) { struct cxl_region_params *p = &cxlr->params; @@ -407,6 +805,37 @@ int cxl_mem_ras_features_init(struct cxl_memdev *cxlmd, struct cxl_region *cxlr) ras_features[num_ras_features].scrub_ctx = cxl_ps_ctx; num_ras_features++; + if (!cxlr) { + rc = cxl_mem_get_supported_feature_entry(cxlmd, &cxl_ecs_uuid, &feat_entry); + if (rc < 0) + goto feat_register; + + if (!(feat_entry.attr_flags & CXL_FEAT_ENTRY_FLAG_CHANGABLE)) + goto feat_register; + num_media_frus = feat_entry.get_size/ + sizeof(struct cxl_ecs_rd_attrs); + if (!num_media_frus) + goto feat_register; + + cxl_ecs_ctx = devm_kzalloc(&cxlmd->dev, sizeof(*cxl_ecs_ctx), GFP_KERNEL); + if (!cxl_ecs_ctx) + goto feat_register; + *cxl_ecs_ctx = (struct cxl_ecs_context) { + .get_feat_size = feat_entry.get_size, + .set_feat_size = feat_entry.set_size, + .num_media_frus = num_media_frus, + .cxlmd = cxlmd, + }; + + ras_features[num_ras_features].feat = ras_feat_ecs; + ras_features[num_ras_features].ecs_ops = &cxl_ecs_ops; + ras_features[num_ras_features].ecs_ctx = cxl_ecs_ctx; + ras_features[num_ras_features].ecs_info.num_media_frus = num_media_frus; + num_ras_features++; + } + +feat_register: + return edac_ras_dev_register(&cxlmd->dev, cxl_dev_name, NULL, num_ras_features, ras_features); } From patchwork Tue Jul 16 15:03:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13734597 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 2752DC3DA49 for ; Tue, 16 Jul 2024 15:04:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 85A306B009B; Tue, 16 Jul 2024 11:04:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E0F56B009C; Tue, 16 Jul 2024 11:04:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5BDCF6B009D; Tue, 16 Jul 2024 11:04:48 -0400 (EDT) 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 3C8FA6B009B for ; Tue, 16 Jul 2024 11:04:48 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D3F79C068C for ; Tue, 16 Jul 2024 15:04:47 +0000 (UTC) X-FDA: 82345937814.09.1624251 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf28.hostedemail.com (Postfix) with ESMTP id F2EF3C0010 for ; Tue, 16 Jul 2024 15:04:45 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.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=1721142247; 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=F93fuiYNl6Q27hD862498JBBQxXlQqyCf924P+Qz0zk=; b=cFoR2DzrQLbZUSUBns6fH07p8aaPBBiGpxsN+pT0teDJ3N1XCoBVeDYx0y3/5W3Xi7SDg1 0AfJvp4Aq7rZ6YL4cy5LoK7qIOxx7/QTzu/5oXN8nGyn8q0WwtrStBOy2GaKRofFK9mMLB cvz34Y3pPZAyoHl+fsG/O1M3AkgeIMI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721142247; a=rsa-sha256; cv=none; b=2psYc6KbFt92xpjZADB4+GOaXU+SxOX4Kr7MUTILV1KRbYvGuorJAuGnsNaafLABaWxNH6 n/HbeFVUe4sMtcCsNICGc0GS+0tsaKw1H/zLSZzqlAaT5BHbrBRdWkfbCERp3n0QOCA++S EneAb7VEzJuZoe//S0+BA7JBy4qry68= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.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 mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4WNj4b6F0Vz6JB4C; Tue, 16 Jul 2024 23:03:27 +0800 (CST) Received: from lhrpeml500006.china.huawei.com (unknown [7.191.161.198]) by mail.maildlp.com (Postfix) with ESMTPS id AFB331400CF; Tue, 16 Jul 2024 23:04:43 +0800 (CST) Received: from P_UKIT01-A7bmah.china.huawei.com (10.48.159.153) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 16 Jul 2024 16:04:42 +0100 From: To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH v9 09/11] platform: Add __free() based cleanup function for platform_device_put Date: Tue, 16 Jul 2024 16:03:33 +0100 Message-ID: <20240716150336.2042-10-shiju.jose@huawei.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20240716150336.2042-1-shiju.jose@huawei.com> References: <20240716150336.2042-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.48.159.153] X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) To lhrpeml500006.china.huawei.com (7.191.161.198) X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: F2EF3C0010 X-Stat-Signature: pe4fomnz3doxbd3pujm7pfyepaczddyt X-HE-Tag: 1721142285-165609 X-HE-Meta: U2FsdGVkX1/RIwm7UGmzFhBDozsE4cltRiF+VITv+ixAO4g+f5tcl2cWVqjyhqzZ7r0G24iHB77SvJmRap4JDIqpw0N/EkNfBNZNiWvM0brcNW2owIAwcM7g7hPFstc2ez+Un55OMbvg5y4u9XryLtVQdLqMti7RhBTcohzPKDyDlHPA/FbNqtcRrbWg05oNdHRgq694E5MIYz3Wn2Ll+qxTK2fEtoS3pCfUf26/72XhH2Aoyf8oHEfxQRMz5FD+Ia683dj2NrB6vchtZMwuMDcDzR5KpvHfGkqtyAg7CJuuAhkU/z6IMcfo2U/KQlS5jlGub7P+T8LoBAfCCNYf/HdxeLS7GxTRa8Wea3nx5Qzw65kTfzwhXlMs4ZfcWHhVzbTcGf1FKT0j+u+KeVyunO7kVWL96PTYWNDvuxh+D1WzIYMKEzVW9y2BKAvc7eWUF1Rcc7qz+3SqM+VEp3EjlLfEVO8GA35VUn3ziPjK2j9/BbGjsLXuIyRrs74xA4Yn3uAtbIMLIFzB9EJA5QRRlo2VXE/U4fR5WxVKLvH+2rUlLwmbEJnJbcU6EK60J++vAcU/+6ONmB3S8W1zqOVOiWurbCU7lyCV/3Z8TETJTnHB79oTUA7gC2QsGLbqFCd9eEIIHSQf5uCScs4TnurSg1NI5b93c/uAYmu4BwgX45s5voLAtuMZ2dcgiZOWyXWCdDFv8Iz7vQTNyByp87BB6lIZtJnBu2Lc2O6INIPS1A5Ch2sE+HJa1xk71DB9rv1frydMqEcDdN43mzrpcm9WGZWGiqbb06Hvxnjt4cI2UGFdkxsnv6yXQNZ6oe10N9RuE5ENJgm1yQK/Mez+GM7WnYWI48vVwLHXpw9Dd7t/1QJDlZzO7ohMuILR57StzlDmvDKKVB+xasW/ZA7FbFO2FA+JH73S59c08mZRkgCm7GmpNcBYTMBKnNo1wON/scaXMn0eHKtiZ9pq4t6xtwt IepoIKTv JWBTG/M7wtyz7ZGmWZ+KhGK/bvbhizh3cUm8uGM+yUhkuVlyslUgYQz4YzUYBMiptQAcPtLMqPAfLiAllS+itx97SpAsYT002y0B9lBqRkbby8lFuGcbA3VKkJSmFNYF2Iy1PxLKdnqrc2LKEnjpTaxS/qIKmXL5dSxQuUBIPjHMa4b7GVaKQB0NGwVrsJXC9kUEBdSooKUabhBd87T4N7LB0HWFAx8UBz/PS2dji38J+ZuIq96kPxUniMdc509akdBiNuIun6gbF0uynXQYJXLqIYjkIo+oVYDRAMyGr0/F0+/w= 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: Jonathan Cameron Add __free() based cleanup function for platform_device_put(). Signed-off-by: Jonathan Cameron Signed-off-by: Shiju Jose --- include/linux/platform_device.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h index 7a41c72c1959..1ddc35623b4c 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -232,6 +232,7 @@ extern int platform_device_add_data(struct platform_device *pdev, extern int platform_device_add(struct platform_device *pdev); extern void platform_device_del(struct platform_device *pdev); extern void platform_device_put(struct platform_device *pdev); +DEFINE_FREE(platform_device_put, struct platform_device *, if (_T) platform_device_put(_T)) struct platform_driver { int (*probe)(struct platform_device *); From patchwork Tue Jul 16 15:03:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13734598 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 15881C3DA49 for ; Tue, 16 Jul 2024 15:04:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E4CF76B009D; Tue, 16 Jul 2024 11:04:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DD4926B009F; Tue, 16 Jul 2024 11:04:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C271B6B00A0; Tue, 16 Jul 2024 11:04:50 -0400 (EDT) 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 9C37F6B009D for ; Tue, 16 Jul 2024 11:04:50 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5866F1617E0 for ; Tue, 16 Jul 2024 15:04:50 +0000 (UTC) X-FDA: 82345937940.05.52AE5D5 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf26.hostedemail.com (Postfix) with ESMTP id 425F1140036 for ; Tue, 16 Jul 2024 15:04:47 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; spf=pass (imf26.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=1721142249; 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=El2paasyFs22ix+F1WoXmsahUn9sIkFwVagGd1Lm9mI=; b=w7PhxNIMzj83mRjrMtS6bzVPCHbCHK0+hATEnIfcFXL3R8udHZiJe8LIKumOrZQN4ZeUst aEWRuR61VMq+M9eFg7z0oHzrKbjmVX9Ni7TyoJJP/GoCuzGCJgO5/n2q76I6C5MZyB1Asw y5A0lx3ic4MOhlmJJxZW/71Ccsgjg6g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721142249; a=rsa-sha256; cv=none; b=lSGEpAKcOWP9/rpsztxSp5SiOCE7JHdfX6Y4K0S/+HSv3LeKOQMyovB0uJb6eBszBMv1oa HMpN6O10xqjK0yVCqlDn3FV3q3YJJyWkwa9B5XByIBL5rU7xBV9aA99lVNGpOCDNehUyu6 UsRnGD+rMQmPpfZjfioaWh0pDdNU2dE= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; spf=pass (imf26.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 mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4WNj4f0mv9z6JB50; Tue, 16 Jul 2024 23:03:30 +0800 (CST) Received: from lhrpeml500006.china.huawei.com (unknown [7.191.161.198]) by mail.maildlp.com (Postfix) with ESMTPS id E5A2A1400CF; Tue, 16 Jul 2024 23:04:45 +0800 (CST) Received: from P_UKIT01-A7bmah.china.huawei.com (10.48.159.153) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 16 Jul 2024 16:04:44 +0100 From: To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH v9 10/11] ACPI:RAS2: Add ACPI RAS2 driver Date: Tue, 16 Jul 2024 16:03:34 +0100 Message-ID: <20240716150336.2042-11-shiju.jose@huawei.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20240716150336.2042-1-shiju.jose@huawei.com> References: <20240716150336.2042-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.48.159.153] X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) To lhrpeml500006.china.huawei.com (7.191.161.198) X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 425F1140036 X-Stat-Signature: ebngzfd8tqr9jqos95hz9amp63fpjbfb X-HE-Tag: 1721142287-131934 X-HE-Meta: U2FsdGVkX1/WqUpMvVQvfnhH4HiQpeaYdbAX56L+U830KtV/jrE+ShL1NTr+cPVECh+8001oWmFGfzLBkbyaxPa+Gc10pZsq56UC29sbu2t7nHlb3s6IR4v7BrFfZo81/Xh6iMS1c5CqQxnRsY4XFSXq2e1sVWr27Hp5wGUK+1lqbB39D19M3NRNBDlTTjNxQG2lcifZxpwqGY97ET7NRsdVziTHsf2kTiOHGrqymfyRf1jKln8x/loSziXpizxZbiTroBPu5M5mYXq3S4p3zxVQiTB3uvi6ekYp6OcfzslAjQlz+gGY2SeZz+K5ptRs25tuhqNiuN+LZzQlB2vGn/cNxxlf/G4S3ADBcr4223xLH4Yg+wwlh6elaqbfEa3A1+aUSNkXKdy5LGtzB9WdKCv0PoDEOZ3lPxnPwSIjP9DhHbBkBDmqxtXeGHmSb0EbYplRjhmLJ0G6TRHCI3jPsPr2aAt2BpcWu8IwboW0lWsClJX3BszSiqw7VNDo56gIueOicTNXucMdZ0KyMVrBJK8qX/Rhz2a2o/DAsxo3VIHyyA+ceI/pcr+ZvM/f6CvVBiavgG5HyCDfCMcoLXDFZYvTKPyr+w2WuV0cSNWLaPfe+5RYxpu0z3sayqLBxUDHV9dblxdg51NKaOLmtiok1OAzho8k59xFG8keV85JhjjPcbQp0uho1wU1DVka+RocPI7J1R9JwHXSMboFRDNaT5KnZvVsZ+T9KveFGiq1/WeNOEMSyEDohFZDR79LRslzE01YMJDlVu1lBxkW+uowG4WdMsBOPJ1X5VHuEnBvpClUvPXJUFKOPqMHAqShaB1m5O7m2GD/g5xOYZ/YnfGXnmc4s78TVqeZXpP4qEe2ssCtpPwjiESYlDLpbzZNhW9zdk1ZkdFYI3Fshz1+++9XbAS8CTuDQ/t+5qc8dRa3qPrLVMe3IAJMyTD3yAa4homA4difdByuqpo2TJEzLQr CYtkkMfp nOviQd0wF2gPbPL+5pE8l1j0Syxr3rzD48JPuYa2s7sePgntPiAaEjo9U/rGK5c8RstEzlgfDzDE6QaAtT2biOnYuCzf52LaWo0EoT2pv8DeOi14Ajp1U1d60H1jsgMx5/Dsjqph6RBd3+EBO2/9HrFixwC+hY3fTtvFXZsjSq0fSiWgx+0Z3zNuNk9r62Mj8yq2+JDQVlCMz5hHk+qbOmrppFfF8xpmdZ0Sq1149lUB4DtzgxDK+HMyOPXKmRJfiNHNoQooV1cRp8OA= 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 ACPI RAS2 feature table (RAS2) defined in the ACPI 6.5 Specification, section 5.2.21. Driver contains RAS2 Init, which extracts the RAS2 table and driver adds platform device for each memory features which binds to the RAS2 memory driver. Driver uses PCC mailbox to communicate with the ACPI HW and the driver adds OSPM interfaces to send RAS2 commands. Co-developed-by: A Somasundaram Signed-off-by: A Somasundaram Co-developed-by: Jonathan Cameron Signed-off-by: Jonathan Cameron Signed-off-by: Shiju Jose --- drivers/acpi/Kconfig | 10 + drivers/acpi/Makefile | 1 + drivers/acpi/ras2.c | 391 +++++++++++++++++++++++++++++++++++++++ include/acpi/ras2_acpi.h | 59 ++++++ 4 files changed, 461 insertions(+) create mode 100755 drivers/acpi/ras2.c create mode 100644 include/acpi/ras2_acpi.h diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index e3a7c2aedd5f..482080f1f0c5 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -284,6 +284,16 @@ config ACPI_CPPC_LIB If your platform does not support CPPC in firmware, leave this option disabled. +config ACPI_RAS2 + bool "ACPI RAS2 driver" + select MAILBOX + select PCC + help + The driver adds support for ACPI RAS2 feature table(extracts RAS2 + table from OS system table) and OSPM interfaces to send RAS2 + commands via PCC mailbox subspace. Driver adds platform device for + the RAS2 memory features which binds to the RAS2 memory driver. + config ACPI_PROCESSOR tristate "Processor" depends on X86 || ARM64 || LOONGARCH || RISCV diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 39ea5cfa8326..4d62633ee4c2 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -99,6 +99,7 @@ obj-$(CONFIG_ACPI_EC_DEBUGFS) += ec_sys.o obj-$(CONFIG_ACPI_BGRT) += bgrt.o obj-$(CONFIG_ACPI_CPPC_LIB) += cppc_acpi.o obj-$(CONFIG_ACPI_SPCR_TABLE) += spcr.o +obj-$(CONFIG_ACPI_RAS2) += ras2.o obj-$(CONFIG_ACPI_DEBUGGER_USER) += acpi_dbg.o obj-$(CONFIG_ACPI_PPTT) += pptt.o obj-$(CONFIG_ACPI_PFRUT) += pfr_update.o pfr_telemetry.o diff --git a/drivers/acpi/ras2.c b/drivers/acpi/ras2.c new file mode 100755 index 000000000000..07fe8ac02d25 --- /dev/null +++ b/drivers/acpi/ras2.c @@ -0,0 +1,391 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Implementation of ACPI RAS2 driver. + * + * Copyright (c) 2024 HiSilicon Limited. + * + * Support for RAS2 - ACPI 6.5 Specification, section 5.2.21 + * + * Driver contains ACPI RAS2 init, which extracts the ACPI RAS2 table and + * get the PCC channel subspace for communicating with the ACPI compliant + * HW platform which supports ACPI RAS2. Driver adds platform devices + * for each RAS2 memory feature which binds to the memory ACPI RAS2 driver. + */ + +#define pr_fmt(fmt) "ACPI RAS2: " fmt + +#include +#include +#include +#include +#include +#include + +/* + * Arbitrary Retries for PCC commands because the + * remote processor could be much slower to reply. + */ +#define RAS2_NUM_RETRIES 600 + +#define RAS2_FEATURE_TYPE_MEMORY 0x00 + +/* global variables for the RAS2 PCC subspaces */ +static DEFINE_MUTEX(ras2_pcc_subspace_lock); +static LIST_HEAD(ras2_pcc_subspaces); + +static int ras2_report_cap_error(u32 cap_status) +{ + switch (cap_status) { + case ACPI_RAS2_NOT_VALID: + case ACPI_RAS2_NOT_SUPPORTED: + return -EPERM; + case ACPI_RAS2_BUSY: + return -EBUSY; + case ACPI_RAS2_FAILED: + case ACPI_RAS2_ABORTED: + case ACPI_RAS2_INVALID_DATA: + return -EINVAL; + default: /* 0 or other, Success */ + return 0; + } +} + +static int ras2_check_pcc_chan(struct ras2_pcc_subspace *pcc_subspace) +{ + struct acpi_ras2_shared_memory __iomem *generic_comm_base = pcc_subspace->pcc_comm_addr; + ktime_t next_deadline = ktime_add(ktime_get(), pcc_subspace->deadline); + u32 cap_status; + u16 status; + u32 ret; + + while (!ktime_after(ktime_get(), next_deadline)) { + /* + * As per ACPI spec, the PCC space will be initialized by + * platform and should have set the command completion bit when + * PCC can be used by OSPM + */ + status = readw_relaxed(&generic_comm_base->status); + if (status & RAS2_PCC_CMD_ERROR) { + cap_status = readw_relaxed(&generic_comm_base->set_capabilities_status); + ret = ras2_report_cap_error(cap_status); + + status &= ~RAS2_PCC_CMD_ERROR; + writew_relaxed(status, &generic_comm_base->status); + return ret; + } + if (status & RAS2_PCC_CMD_COMPLETE) + return 0; + /* + * Reducing the bus traffic in case this loop takes longer than + * a few retries. + */ + msleep(10); + } + + return -EIO; +} + +/** + * ras2_send_pcc_cmd() - Send RAS2 command via PCC channel + * @ras2_ctx: pointer to the ras2 context structure + * @cmd: command to send + * + * Returns: 0 on success, an error otherwise + */ +int ras2_send_pcc_cmd(struct ras2_scrub_ctx *ras2_ctx, u16 cmd) +{ + struct ras2_pcc_subspace *pcc_subspace = ras2_ctx->pcc_subspace; + struct acpi_ras2_shared_memory *generic_comm_base = pcc_subspace->pcc_comm_addr; + static ktime_t last_cmd_cmpl_time, last_mpar_reset; + struct mbox_chan *pcc_channel; + unsigned int time_delta; + static int mpar_count; + int ret; + + guard(mutex)(&ras2_pcc_subspace_lock); + ret = ras2_check_pcc_chan(pcc_subspace); + if (ret < 0) + return ret; + pcc_channel = pcc_subspace->pcc_chan->mchan; + + /* + * Handle the Minimum Request Turnaround Time(MRTT) + * "The minimum amount of time that OSPM must wait after the completion + * of a command before issuing the next command, in microseconds" + */ + if (pcc_subspace->pcc_mrtt) { + time_delta = ktime_us_delta(ktime_get(), last_cmd_cmpl_time); + if (pcc_subspace->pcc_mrtt > time_delta) + udelay(pcc_subspace->pcc_mrtt - time_delta); + } + + /* + * Handle the non-zero Maximum Periodic Access Rate(MPAR) + * "The maximum number of periodic requests that the subspace channel can + * support, reported in commands per minute. 0 indicates no limitation." + * + * This parameter should be ideally zero or large enough so that it can + * handle maximum number of requests that all the cores in the system can + * collectively generate. If it is not, we will follow the spec and just + * not send the request to the platform after hitting the MPAR limit in + * any 60s window + */ + if (pcc_subspace->pcc_mpar) { + if (mpar_count == 0) { + time_delta = ktime_ms_delta(ktime_get(), last_mpar_reset); + if (time_delta < 60 * MSEC_PER_SEC) { + dev_dbg(ras2_ctx->dev, + "PCC cmd not sent due to MPAR limit"); + return -EIO; + } + last_mpar_reset = ktime_get(); + mpar_count = pcc_subspace->pcc_mpar; + } + mpar_count--; + } + + /* Write to the shared comm region. */ + writew_relaxed(cmd, &generic_comm_base->command); + + /* Flip CMD COMPLETE bit */ + writew_relaxed(0, &generic_comm_base->status); + + /* Ring doorbell */ + ret = mbox_send_message(pcc_channel, &cmd); + if (ret < 0) { + dev_err(ras2_ctx->dev, + "Err sending PCC mbox message. cmd:%d, ret:%d\n", + cmd, ret); + return ret; + } + + /* + * If Minimum Request Turnaround Time is non-zero, we need + * to record the completion time of both READ and WRITE + * command for proper handling of MRTT, so we need to check + * for pcc_mrtt in addition to CMD_READ + */ + if (cmd == RAS2_PCC_CMD_EXEC || pcc_subspace->pcc_mrtt) { + ret = ras2_check_pcc_chan(pcc_subspace); + if (pcc_subspace->pcc_mrtt) + last_cmd_cmpl_time = ktime_get(); + } + + if (pcc_channel->mbox->txdone_irq) + mbox_chan_txdone(pcc_channel, ret); + else + mbox_client_txdone(pcc_channel, ret); + + return ret >= 0 ? 0 : ret; +} +EXPORT_SYMBOL_GPL(ras2_send_pcc_cmd); + +static int ras2_register_pcc_channel(struct device *dev, struct ras2_scrub_ctx *ras2_ctx, + int pcc_subspace_id) +{ + struct acpi_pcct_hw_reduced *ras2_ss; + struct mbox_client *ras2_mbox_cl; + struct pcc_mbox_chan *pcc_chan; + struct ras2_pcc_subspace *pcc_subspace; + + if (pcc_subspace_id < 0) + return -EINVAL; + + mutex_lock(&ras2_pcc_subspace_lock); + list_for_each_entry(pcc_subspace, &ras2_pcc_subspaces, elem) { + if (pcc_subspace->pcc_subspace_id == pcc_subspace_id) { + ras2_ctx->pcc_subspace = pcc_subspace; + pcc_subspace->ref_count++; + mutex_unlock(&ras2_pcc_subspace_lock); + return 0; + } + } + mutex_unlock(&ras2_pcc_subspace_lock); + + pcc_subspace = kcalloc(1, sizeof(*pcc_subspace), GFP_KERNEL); + if (!pcc_subspace) + return -ENOMEM; + pcc_subspace->pcc_subspace_id = pcc_subspace_id; + ras2_mbox_cl = &pcc_subspace->mbox_client; + ras2_mbox_cl->dev = dev; + ras2_mbox_cl->knows_txdone = true; + + pcc_chan = pcc_mbox_request_channel(ras2_mbox_cl, pcc_subspace_id); + if (IS_ERR(pcc_chan)) { + kfree(pcc_subspace); + return PTR_ERR(pcc_chan); + } + pcc_subspace->pcc_chan = pcc_chan; + ras2_ss = pcc_chan->mchan->con_priv; + pcc_subspace->comm_base_addr = ras2_ss->base_address; + + /* + * ras2_ss->latency is just a Nominal value. In reality + * the remote processor could be much slower to reply. + * So add an arbitrary amount of wait on top of Nominal. + */ + pcc_subspace->deadline = ns_to_ktime(RAS2_NUM_RETRIES * ras2_ss->latency * + NSEC_PER_USEC); + pcc_subspace->pcc_mrtt = ras2_ss->min_turnaround_time; + pcc_subspace->pcc_mpar = ras2_ss->max_access_rate; + pcc_subspace->pcc_comm_addr = acpi_os_ioremap(pcc_subspace->comm_base_addr, + ras2_ss->length); + /* Set flag so that we dont come here for each CPU. */ + pcc_subspace->pcc_channel_acquired = true; + + mutex_lock(&ras2_pcc_subspace_lock); + list_add(&pcc_subspace->elem, &ras2_pcc_subspaces); + pcc_subspace->ref_count++; + mutex_unlock(&ras2_pcc_subspace_lock); + ras2_ctx->pcc_subspace = pcc_subspace; + + return 0; +} + +static void ras2_unregister_pcc_channel(void *ctx) +{ + struct ras2_scrub_ctx *ras2_ctx = ctx; + struct ras2_pcc_subspace *pcc_subspace = ras2_ctx->pcc_subspace; + + if (!pcc_subspace || !pcc_subspace->pcc_chan) + return; + + guard(mutex)(&ras2_pcc_subspace_lock); + if (pcc_subspace->ref_count > 0) + pcc_subspace->ref_count--; + if (!pcc_subspace->ref_count) { + list_del(&pcc_subspace->elem); + pcc_mbox_free_channel(pcc_subspace->pcc_chan); + kfree(pcc_subspace); + } +} + +/** + * devm_ras2_register_pcc_channel() - Register RAS2 PCC channel + * @dev: pointer to the ras2 device + * @ras2_ctx: pointer to the ras2 context structure + * @pcc_subspace_id: identifier of the RAS2 PCC channel. + * + * Returns: 0 on success, an error otherwise + */ +int devm_ras2_register_pcc_channel(struct device *dev, struct ras2_scrub_ctx *ras2_ctx, + int pcc_subspace_id) +{ + int ret; + + ret = ras2_register_pcc_channel(dev, ras2_ctx, pcc_subspace_id); + if (ret) + return ret; + + return devm_add_action_or_reset(dev, ras2_unregister_pcc_channel, ras2_ctx); +} +EXPORT_SYMBOL_NS_GPL(devm_ras2_register_pcc_channel, ACPI_RAS2); + +static struct platform_device *ras2_add_platform_device(char *name, int channel) +{ + int ret; + struct platform_device *pdev __free(platform_device_put) = + platform_device_alloc(name, PLATFORM_DEVID_AUTO); + if (!pdev) + return ERR_PTR(-ENOMEM); + + ret = platform_device_add_data(pdev, &channel, sizeof(channel)); + if (ret) + return ERR_PTR(ret); + + ret = platform_device_add(pdev); + if (ret) + return ERR_PTR(ret); + + return_ptr(pdev); +} + +static int __init ras2_acpi_init(void) +{ + struct acpi_table_header *pAcpiTable = NULL; + struct acpi_ras2_pcc_desc *pcc_desc_list; + struct acpi_table_ras2 *pRas2Table; + struct platform_device *pdev; + int pcc_subspace_id; + acpi_size ras2_size; + acpi_status status; + u8 count = 0, i; + int ret; + + status = acpi_get_table("RAS2", 0, &pAcpiTable); + if (ACPI_FAILURE(status) || !pAcpiTable) { + pr_err("ACPI RAS2 driver failed to initialize, get table failed\n"); + return -EINVAL; + } + + ras2_size = pAcpiTable->length; + if (ras2_size < sizeof(struct acpi_table_ras2)) { + pr_err("ACPI RAS2 table present but broken (too short #1)\n"); + ret = -EINVAL; + goto free_ras2_table; + } + + pRas2Table = (struct acpi_table_ras2 *)pAcpiTable; + if (pRas2Table->num_pcc_descs <= 0) { + pr_err("ACPI RAS2 table does not contain PCC descriptors\n"); + ret = -EINVAL; + goto free_ras2_table; + } + + struct platform_device **pdev_list __free(kfree) = + kcalloc(pRas2Table->num_pcc_descs, sizeof(*pdev_list), + GFP_KERNEL); + if (!pdev_list) { + ret = -ENOMEM; + goto free_ras2_table; + } + + pcc_desc_list = (struct acpi_ras2_pcc_desc *)(pRas2Table + 1); + /* Double scan for the case of only one actual controller */ + pcc_subspace_id = -1; + count = 0; + for (i = 0; i < pRas2Table->num_pcc_descs; i++, pcc_desc_list++) { + if (pcc_desc_list->feature_type != RAS2_FEATURE_TYPE_MEMORY) + continue; + if (pcc_subspace_id == -1) { + pcc_subspace_id = pcc_desc_list->channel_id; + count++; + } + if (pcc_desc_list->channel_id != pcc_subspace_id) + count++; + } + if (count == 1) { + pdev = ras2_add_platform_device("acpi_ras2", pcc_subspace_id); + if (!pdev) { + ret = -ENODEV; + goto free_ras2_pdev; + } + pdev_list[0] = pdev; + return 0; + } + + count = 0; + for (i = 0; i < pRas2Table->num_pcc_descs; i++, pcc_desc_list++) { + if (pcc_desc_list->feature_type != RAS2_FEATURE_TYPE_MEMORY) + continue; + pcc_subspace_id = pcc_desc_list->channel_id; + /* Add the platform device and bind ACPI RAS2 memory driver */ + pdev = ras2_add_platform_device("acpi_ras2", pcc_subspace_id); + if (!pdev) + goto free_ras2_pdev; + pdev_list[count++] = pdev; + } + + acpi_put_table(pAcpiTable); + return 0; + +free_ras2_pdev: + for (i = count; i >= 0; i++) + platform_device_put(pdev_list[i]); + +free_ras2_table: + acpi_put_table(pAcpiTable); + + return ret; +} +late_initcall(ras2_acpi_init) diff --git a/include/acpi/ras2_acpi.h b/include/acpi/ras2_acpi.h new file mode 100644 index 000000000000..cb99201f12d2 --- /dev/null +++ b/include/acpi/ras2_acpi.h @@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * RAS2 ACPI driver header file + * + * (C) Copyright 2014, 2015 Hewlett-Packard Enterprises + * + * Copyright (c) 2024 HiSilicon Limited + */ + +#ifndef _RAS2_ACPI_H +#define _RAS2_ACPI_H + +#include +#include +#include +#include + +#define RAS2_PCC_CMD_COMPLETE BIT(0) +#define RAS2_PCC_CMD_ERROR BIT(2) + +/* RAS2 specific PCC commands */ +#define RAS2_PCC_CMD_EXEC 0x01 + +struct device; + +/* Data structures for PCC communication and RAS2 table */ +struct pcc_mbox_chan; + +struct ras2_pcc_subspace { + int pcc_subspace_id; + struct mbox_client mbox_client; + struct pcc_mbox_chan *pcc_chan; + struct acpi_ras2_shared_memory __iomem *pcc_comm_addr; + u64 comm_base_addr; + bool pcc_channel_acquired; + ktime_t deadline; + unsigned int pcc_mpar; + unsigned int pcc_mrtt; + struct list_head elem; + u16 ref_count; +}; + +struct ras2_scrub_ctx { + struct device *dev; + struct ras2_pcc_subspace *pcc_subspace; + int id; + struct device *scrub_dev; + bool bg; + u64 base, size; + u8 schrs, schrs_min, schrs_max; /* schrs - scrub cycle in hours */ + /* Lock to provide mutually exclusive access to PCC channel */ + struct mutex lock; +}; + +int ras2_send_pcc_cmd(struct ras2_scrub_ctx *ras2_ctx, u16 cmd); +int devm_ras2_register_pcc_channel(struct device *dev, struct ras2_scrub_ctx *ras2_ctx, + int pcc_subspace_id); + +#endif /* _RAS2_ACPI_H */ From patchwork Tue Jul 16 15:03:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13734600 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 7AC31C3DA59 for ; Tue, 16 Jul 2024 15:05:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 439466B00A0; Tue, 16 Jul 2024 11:04:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C2706B00A1; Tue, 16 Jul 2024 11:04:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C8066B00A2; Tue, 16 Jul 2024 11:04:53 -0400 (EDT) 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 E8E8D6B00A0 for ; Tue, 16 Jul 2024 11:04:52 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 91455A2042 for ; Tue, 16 Jul 2024 15:04:52 +0000 (UTC) X-FDA: 82345938024.09.0E37D76 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf01.hostedemail.com (Postfix) with ESMTP id 6EE1440021 for ; Tue, 16 Jul 2024 15:04:50 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.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=1721142239; 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=DskutYr5J1teJN7LXhLPkLCzJwMmwuimPXH2R8B5q24=; b=vzcVoXYTFIUJXuijCWZLL5eW7jrNPpkS2rBSHIS9bWSqy8yggTfDNZqfQwiq9T4XkstL3h oNoXLClZenLJOiPdPcKatLk/9F/V6XNxNtXYX38BpudxrfYqTWZ+10TuqaV8X8SYhihgad /9c3VhxjelZnCjcLh2RuVv2ecOuvQu4= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.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=1721142239; a=rsa-sha256; cv=none; b=uHREu9dAeLfqIlQjGghxKJIPov9ONnKmGaru1/rG63hGHACcziOYVFHPJzKg/EIsZ+Wogc saFwNwq120bn9mnnZUso16c5ix/DSXAna3U4EiDGn8lsHXRhlFYQFT/9bveMVx1Wxe8VhP xSBW7FHGcUFi6FhT6oCfXNZqKMqlFJU= Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4WNj473gJ3z67M9n; Tue, 16 Jul 2024 23:03:03 +0800 (CST) Received: from lhrpeml500006.china.huawei.com (unknown [7.191.161.198]) by mail.maildlp.com (Postfix) with ESMTPS id 618D61400CF; Tue, 16 Jul 2024 23:04:48 +0800 (CST) Received: from P_UKIT01-A7bmah.china.huawei.com (10.48.159.153) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 16 Jul 2024 16:04:46 +0100 From: To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH v9 11/11] ras: scrub: ACPI RAS2: Add memory ACPI RAS2 driver Date: Tue, 16 Jul 2024 16:03:35 +0100 Message-ID: <20240716150336.2042-12-shiju.jose@huawei.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20240716150336.2042-1-shiju.jose@huawei.com> References: <20240716150336.2042-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.48.159.153] X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) To lhrpeml500006.china.huawei.com (7.191.161.198) X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6EE1440021 X-Stat-Signature: zwhrhzgtpap5oyt43tiqhi1axriuuxfy X-Rspam-User: X-HE-Tag: 1721142290-696442 X-HE-Meta: U2FsdGVkX19GYeDkSJ8kgFTDeh2Ilcwesg/5aLshyffEZxsKljWYYQurWmLhU9fqVaglUQaLip6JCHnxZKobVfHYgxKz7EYM/YHeDhcSf6P5QEsVziXXuVPEuLfH0DjQo+fcecOMvX1Zd6wurx/PVuNcaNUyDoWtsu7NmE/pBkMPZue4A3SR2kp66cc1KhGcanAGjgoPcAdGt4j7jRxOkGu9B+DbD15hlB0s9vp7UmbyVh5CS3z3kA6JYJNKtG7sQFgxlR1ewbfhiIKJ7WDVCEdZJPc2kQaV3gtQIMS9OMo02sEhbRmT34X+ErnDhn47SYjWv42z76sWS/V5SdJgQQAFbD9RSJ8m96gesepprpRv0ViqkHJ3rBSVl+jFNRVXggfnZ01WL5/NQYJZ1lwIsQGrFO7MO+EXX1BCHbspiGL3Ja0gYEdpRTo1nBYeLW+q2p4bhAylwYVZl2JTqyPn+egP85+nEhm/szqvtcC3UsSezorxaHTM/Zck3j8AwD6onLigF7byEcBxJ57Y36ZeGcFcZchewhvjAM2WFAY3PAf8MrOcOiECkqDcL9K1syF/bEztSHgzSV0AVYuaLX0OmIqxP2wVzcwQSD+vdnZ79x35ScxtXHMZfjXp/ie/O0INE8pjD0mCdXc/WcutTPV5KFIcUQkKoZVY6WgMbFZhcm6iUI/hypIhr485BosWrRavGKrnLoL8OJ4BbrMbBMSS5CXO3c8lw+ZfzBbdpHu9KObrkqIu8W1ZxtKosBeQGKtl1yoQtXgyLtp2PO0JHjZiUg4u9OhxE0/QteQY6ceYmZSEEd/EM/XEUFf1Ou24cuIz6cSEUbfXjmi1KtHFUquqgEL8TUBT5FEyxNSBI7K/dlTH1rR4/lrsLy9PpHSaAOaAtthPrvk7vGYKleCnys2hK4C9ikz43yw+hqIP1u7+sCFKxp8hdxWcN3kRGJ9yY0ZM8MxrLc3eV9KUuRXGucX wVg1wTXg /I1aekhJAb8hLc4CxHsZG+e+3UW6ZRhmL/SJrVXqU/EfmWFB4xud6+4CDpTbV799MrO48tTsNHMG563RXwvz7HBX0yajBfBL5rYAr0jjrdwTZylKwJYdY65TKJF/kCCMmnOOJEQThDJHInFP04UF6z0MGhqwnTybIf4/woenRhrX5l8gmUYFRShY+qW6IUAr1u0PYKJSdCbMpmV8aliT/sh+nqA== 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 Memory ACPI RAS2 driver binds to the platform device add by the ACPI RAS2 table parser. Driver uses a PCC subspace for communicating with the ACPI compliant platform to provide control of memory scrub parameters to the userspace via the edac scrub. Get the scrub attr descriptors from the EDAC scrub and register with EDAC RAS feature driver to expose sysfs scrub control attributes to the userspace. For example scrub control for the RAS2 memory device is exposed in /sys/bus/edac/devices/acpi_ras2_mem0/scrub/ Co-developed-by: Jonathan Cameron Signed-off-by: Jonathan Cameron Signed-off-by: Shiju Jose --- Documentation/scrub/edac-scrub.rst | 37 +++ drivers/ras/Kconfig | 10 + drivers/ras/Makefile | 1 + drivers/ras/acpi_ras2.c | 401 +++++++++++++++++++++++++++++ 4 files changed, 449 insertions(+) create mode 100644 drivers/ras/acpi_ras2.c diff --git a/Documentation/scrub/edac-scrub.rst b/Documentation/scrub/edac-scrub.rst index cf7d8b130204..da9cd2e73687 100644 --- a/Documentation/scrub/edac-scrub.rst +++ b/Documentation/scrub/edac-scrub.rst @@ -68,3 +68,40 @@ root@localhost:~# cat /sys/bus/edac/devices/cxl_region0/scrub/enable_background root@localhost:~# echo 0 > /sys/bus/edac/devices/cxl_region0/scrub/enable_background root@localhost:~# cat /sys/bus/edac/devices/cxl_region0/scrub/enable_background 0 + +2. RAS2 +2.1 On demand scrubbing for a specific memory region. +root@localhost:~# echo 0x120000 > /sys/bus/edac/devices/acpi_ras2_mem0/scrub/addr_range_base +root@localhost:~# echo 0x150000 > /sys/bus/edac/devices/acpi_ras2_mem0/scrub/addr_range_size +root@localhost:~# cat /sys/bus/edac/devices/acpi_ras2_mem0/scrub/cycle_in_hours_range +0x1-0x18 +root@localhost:~# cat /sys/bus/edac/devices/acpi_ras2_mem0/scrub/cycle_in_hours +0xa +root@localhost:~# echo 15 > /sys/bus/edac/devices/acpi_ras2_mem0/scrub/cycle_in_hours +root@localhost:~# echo 1 > /sys/bus/edac/devices/acpi_ras2_mem0/scrub/enable_on_demand +root@localhost:~# cat /sys/bus/edac/devices/acpi_ras2_mem0/scrub/enable_on_demand +1 +root@localhost:~# cat /sys/bus/edac/devices/acpi_ras2_mem0/scrub/cycle_in_hours +0xf +root@localhost:~# cat /sys/bus/edac/devices/acpi_ras2_mem0/scrub/addr_range_base +0x120000 +root@localhost:~# cat //sys/bus/edac/devices/acpi_ras2_mem0/scrub/addr_range_size +0x150000 +root@localhost:~# echo 0 > /sys/bus/edac/devices/acpi_ras2_mem0/scrub/enable_on_demand +root@localhost:~# cat /sys/bus/edac/devices/acpi_ras2_mem0/scrub/enable_on_demand +0 + +2.2 Background scrubbing the entire memory +root@localhost:~# cat /sys/bus/edac/devices/acpi_ras2_mem0/scrub/cycle_in_hours_range +0x1-0x18 +root@localhost:~# cat /sys/bus/edac/devices/acpi_ras2_mem0/scrub/cycle_in_hours +0xa +root@localhost:~# cat /sys/bus/edac/devices/acpi_ras2_mem0/enable_background +0 +root@localhost:~# echo 3 > /sys/bus/edac/devices/acpi_ras2_mem0/scrub/cycle_in_hours +root@localhost:~# echo 1 > /sys/bus/edac/devices/acpi_ras2_mem0/enable_background +root@localhost:~# cat /sys/bus/edac/devices/acpi_ras2_mem0/enable_background +1 +root@localhost:~# cat /sys/bus/edac/devices/acpi_ras2_mem0/scrub/cycle_in_hours +0x3 +root@localhost:~# echo 0 > /sys/bus/edac/devices/acpi_ras2_mem0/enable_background diff --git a/drivers/ras/Kconfig b/drivers/ras/Kconfig index fc4f4bb94a4c..a2635017d80d 100644 --- a/drivers/ras/Kconfig +++ b/drivers/ras/Kconfig @@ -46,4 +46,14 @@ config RAS_FMPM Memory will be retired during boot time and run time depending on platform-specific policies. +config MEM_ACPI_RAS2 + tristate "Memory ACPI RAS2 driver" + depends on ACPI_RAS2 + depends on EDAC + help + The driver binds to the platform device added by the ACPI RAS2 + table parser. Use a PCC channel subspace for communicating with + the ACPI compliant platform to provide control of memory scrub + parameters to the user via the edac scrub. + endif diff --git a/drivers/ras/Makefile b/drivers/ras/Makefile index 11f95d59d397..a0e6e903d6b0 100644 --- a/drivers/ras/Makefile +++ b/drivers/ras/Makefile @@ -2,6 +2,7 @@ obj-$(CONFIG_RAS) += ras.o obj-$(CONFIG_DEBUG_FS) += debugfs.o obj-$(CONFIG_RAS_CEC) += cec.o +obj-$(CONFIG_MEM_ACPI_RAS2) += acpi_ras2.o obj-$(CONFIG_RAS_FMPM) += amd/fmpm.o obj-y += amd/atl/ diff --git a/drivers/ras/acpi_ras2.c b/drivers/ras/acpi_ras2.c new file mode 100644 index 000000000000..49703d8bc4fa --- /dev/null +++ b/drivers/ras/acpi_ras2.c @@ -0,0 +1,401 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * ACPI RAS2 memory driver + * + * Copyright (c) 2024 HiSilicon Limited. + * + */ + +#define pr_fmt(fmt) "MEMORY ACPI RAS2: " fmt + +#include +#include +#include + +#define RAS2_DEV_NUM_RAS_FEATURES 1 + +#define RAS2_SUPPORT_HW_PARTOL_SCRUB BIT(0) +#define RAS2_TYPE_PATROL_SCRUB 0x0000 + +#define RAS2_GET_PATROL_PARAMETERS 0x01 +#define RAS2_START_PATROL_SCRUBBER 0x02 +#define RAS2_STOP_PATROL_SCRUBBER 0x03 + +#define RAS2_PATROL_SCRUB_SCHRS_IN_MASK GENMASK(15, 8) +#define RAS2_PATROL_SCRUB_EN_BACKGROUND BIT(0) +#define RAS2_PATROL_SCRUB_SCHRS_OUT_MASK GENMASK(7, 0) +#define RAS2_PATROL_SCRUB_MIN_SCHRS_OUT_MASK GENMASK(15, 8) +#define RAS2_PATROL_SCRUB_MAX_SCHRS_OUT_MASK GENMASK(23, 16) +#define RAS2_PATROL_SCRUB_FLAG_SCRUBBER_RUNNING BIT(0) + +#define RAS2_SCRUB_NAME_LEN 128 + +struct acpi_ras2_ps_shared_mem { + struct acpi_ras2_shared_memory common; + struct acpi_ras2_patrol_scrub_parameter params; +}; + +static int ras2_is_patrol_scrub_support(struct ras2_scrub_ctx *ras2_ctx) +{ + struct acpi_ras2_shared_memory __iomem *common = (void *) + ras2_ctx->pcc_subspace->pcc_comm_addr; + + guard(mutex)(&ras2_ctx->lock); + common->set_capabilities[0] = 0; + + return common->features[0] & RAS2_SUPPORT_HW_PARTOL_SCRUB; +} + +static int ras2_update_patrol_scrub_params_cache(struct ras2_scrub_ctx *ras2_ctx) +{ + struct acpi_ras2_ps_shared_mem __iomem *ps_sm = (void *) + ras2_ctx->pcc_subspace->pcc_comm_addr; + int ret; + + ps_sm->common.set_capabilities[0] = RAS2_SUPPORT_HW_PARTOL_SCRUB; + ps_sm->params.patrol_scrub_command = RAS2_GET_PATROL_PARAMETERS; + + ret = ras2_send_pcc_cmd(ras2_ctx, RAS2_PCC_CMD_EXEC); + if (ret) { + dev_err(ras2_ctx->dev, "failed to read parameters\n"); + return ret; + } + + ras2_ctx->schrs_min = FIELD_GET(RAS2_PATROL_SCRUB_MIN_SCHRS_OUT_MASK, + ps_sm->params.scrub_params_out); + ras2_ctx->schrs_max = FIELD_GET(RAS2_PATROL_SCRUB_MAX_SCHRS_OUT_MASK, + ps_sm->params.scrub_params_out); + if (!ras2_ctx->bg) { + ras2_ctx->base = ps_sm->params.actual_address_range[0]; + ras2_ctx->size = ps_sm->params.actual_address_range[1]; + } + ras2_ctx->schrs = FIELD_GET(RAS2_PATROL_SCRUB_SCHRS_OUT_MASK, + ps_sm->params.scrub_params_out); + + return 0; +} + +/* Context - lock must be held */ +static int ras2_get_patrol_scrub_running(struct ras2_scrub_ctx *ras2_ctx, + bool *running) +{ + struct acpi_ras2_ps_shared_mem __iomem *ps_sm = (void *) + ras2_ctx->pcc_subspace->pcc_comm_addr; + int ret; + + ps_sm->common.set_capabilities[0] = RAS2_SUPPORT_HW_PARTOL_SCRUB; + ps_sm->params.patrol_scrub_command = RAS2_GET_PATROL_PARAMETERS; + + ret = ras2_send_pcc_cmd(ras2_ctx, RAS2_PCC_CMD_EXEC); + if (ret) { + dev_err(ras2_ctx->dev, "failed to read parameters\n"); + return ret; + } + + *running = ps_sm->params.flags & RAS2_PATROL_SCRUB_FLAG_SCRUBBER_RUNNING; + + return 0; +} + +static int ras2_hw_scrub_write_schrs(struct device *dev, void *drv_data, u64 schrs) +{ + struct ras2_scrub_ctx *ras2_ctx = drv_data; + bool running; + int ret; + + guard(mutex)(&ras2_ctx->lock); + ret = ras2_get_patrol_scrub_running(ras2_ctx, &running); + if (ret) + return ret; + + if (running) + return -EBUSY; + + if (schrs < ras2_ctx->schrs_min || schrs > ras2_ctx->schrs_max) + return -EINVAL; + + ras2_ctx->schrs = schrs; + + return 0; +} + +static int ras2_hw_scrub_read_schrs(struct device *dev, void *drv_data, u64 *schrs) +{ + struct ras2_scrub_ctx *ras2_ctx = drv_data; + + *schrs = ras2_ctx->schrs; + + return 0; +} + +static int ras2_hw_scrub_read_schrs_range(struct device *dev, void *drv_data, u64 *min, u64 *max) +{ + struct ras2_scrub_ctx *ras2_ctx = drv_data; + + *min = ras2_ctx->schrs_min; + *max = ras2_ctx->schrs_max; + + return 0; +} + +static int ras2_hw_scrub_read_range(struct device *dev, void *drv_data, u64 *base, u64 *size) +{ + struct ras2_scrub_ctx *ras2_ctx = drv_data; + + /* + * When BG scrubbing is enabled the actual address range is not valid. + * Return -EBUSY now unless findout a method to retrieve actual full PA range. + */ + if (ras2_ctx->bg) + return -EBUSY; + + *base = ras2_ctx->base; + *size = ras2_ctx->size; + + return 0; +} + +static int ras2_hw_scrub_write_range(struct device *dev, void *drv_data, u64 base, u64 size) +{ + struct ras2_scrub_ctx *ras2_ctx = drv_data; + bool running; + int ret; + + guard(mutex)(&ras2_ctx->lock); + ret = ras2_get_patrol_scrub_running(ras2_ctx, &running); + if (ret) + return ret; + + if (running) + return -EBUSY; + + if (!base || !size) { + dev_warn(dev, "%s: Invalid address range, base=0x%llx size=0x%llx\n", + __func__, base, size); + return -EINVAL; + } + + ras2_ctx->base = base; + ras2_ctx->size = size; + + return 0; +} + +static int ras2_hw_scrub_set_enabled_bg(struct device *dev, void *drv_data, bool enable) +{ + struct ras2_scrub_ctx *ras2_ctx = drv_data; + struct acpi_ras2_ps_shared_mem __iomem *ps_sm = (void *) + ras2_ctx->pcc_subspace->pcc_comm_addr; + bool enabled; + int ret; + + guard(mutex)(&ras2_ctx->lock); + ps_sm->common.set_capabilities[0] = RAS2_SUPPORT_HW_PARTOL_SCRUB; + ret = ras2_get_patrol_scrub_running(ras2_ctx, &enabled); + if (ret) + return ret; + if (enable) { + if (ras2_ctx->bg || enabled) + return -EBUSY; + ps_sm->params.requested_address_range[0] = 0; + ps_sm->params.requested_address_range[1] = 0; + ps_sm->params.scrub_params_in &= ~RAS2_PATROL_SCRUB_SCHRS_IN_MASK; + ps_sm->params.scrub_params_in |= FIELD_PREP(RAS2_PATROL_SCRUB_SCHRS_IN_MASK, + ras2_ctx->schrs); + ps_sm->params.patrol_scrub_command = RAS2_START_PATROL_SCRUBBER; + } else { + if (!ras2_ctx->bg) + return -EPERM; + if (!ras2_ctx->bg && enabled) + return -EBUSY; + ps_sm->params.patrol_scrub_command = RAS2_STOP_PATROL_SCRUBBER; + } + ps_sm->params.scrub_params_in &= ~RAS2_PATROL_SCRUB_EN_BACKGROUND; + ps_sm->params.scrub_params_in |= FIELD_PREP(RAS2_PATROL_SCRUB_EN_BACKGROUND, + enable); + ret = ras2_send_pcc_cmd(ras2_ctx, RAS2_PCC_CMD_EXEC); + if (ret) { + dev_err(ras2_ctx->dev, "%s: failed to enable(%d) background scrubbing\n", + __func__, enable); + return ret; + } + if (enable) { + ras2_ctx->bg = true; + /* Update the cache to account for rounding of supplied parameters and similar */ + ret = ras2_update_patrol_scrub_params_cache(ras2_ctx); + } else { + ret = ras2_update_patrol_scrub_params_cache(ras2_ctx); + ras2_ctx->bg = false; + } + + return ret; +} + +static int ras2_hw_scrub_get_enabled_bg(struct device *dev, void *drv_data, bool *enabled) +{ + struct ras2_scrub_ctx *ras2_ctx = drv_data; + + *enabled = ras2_ctx->bg; + + return 0; +} + +static int ras2_hw_scrub_set_enabled_od(struct device *dev, void *drv_data, bool enable) +{ + struct ras2_scrub_ctx *ras2_ctx = drv_data; + struct acpi_ras2_ps_shared_mem __iomem *ps_sm = (void *) + ras2_ctx->pcc_subspace->pcc_comm_addr; + bool enabled; + int ret; + + guard(mutex)(&ras2_ctx->lock); + ps_sm->common.set_capabilities[0] = RAS2_SUPPORT_HW_PARTOL_SCRUB; + if (ras2_ctx->bg) + return -EBUSY; + ret = ras2_get_patrol_scrub_running(ras2_ctx, &enabled); + if (ret) + return ret; + if (enable) { + if (!ras2_ctx->base || !ras2_ctx->size) { + dev_warn(ras2_ctx->dev, + "%s: Invalid address range, base=0x%llx " + "size=0x%llx\n", __func__, + ras2_ctx->base, ras2_ctx->size); + return -ERANGE; + } + if (enabled) + return -EBUSY; + ps_sm->params.scrub_params_in &= ~RAS2_PATROL_SCRUB_SCHRS_IN_MASK; + ps_sm->params.scrub_params_in |= FIELD_PREP(RAS2_PATROL_SCRUB_SCHRS_IN_MASK, + ras2_ctx->schrs); + ps_sm->params.requested_address_range[0] = ras2_ctx->base; + ps_sm->params.requested_address_range[1] = ras2_ctx->size; + ps_sm->params.scrub_params_in &= ~RAS2_PATROL_SCRUB_EN_BACKGROUND; + ps_sm->params.patrol_scrub_command = RAS2_START_PATROL_SCRUBBER; + } else { + if (!enabled) + return 0; + ps_sm->params.patrol_scrub_command = RAS2_STOP_PATROL_SCRUBBER; + } + + ret = ras2_send_pcc_cmd(ras2_ctx, RAS2_PCC_CMD_EXEC); + if (ret) { + dev_err(ras2_ctx->dev, "failed to enable(%d) the demand scrubbing\n", enable); + return ret; + } + + return ras2_update_patrol_scrub_params_cache(ras2_ctx); +} + +static int ras2_hw_scrub_get_enabled_od(struct device *dev, void *drv_data, bool *enabled) +{ + struct ras2_scrub_ctx *ras2_ctx = drv_data; + + guard(mutex)(&ras2_ctx->lock); + if (ras2_ctx->bg) { + *enabled = false; + return 0; + } + + return ras2_get_patrol_scrub_running(ras2_ctx, enabled); +} + +static int ras2_hw_scrub_get_name(struct device *dev, void *drv_data, char *name) +{ + struct ras2_scrub_ctx *ras2_ctx = drv_data; + + return sysfs_emit(name, "acpi_ras2_mem%d_scrub\n", ras2_ctx->id); +} + +static const struct edac_scrub_ops ras2_scrub_ops = { + .read_range = ras2_hw_scrub_read_range, + .write_range = ras2_hw_scrub_write_range, + .get_enabled_bg = ras2_hw_scrub_get_enabled_bg, + .set_enabled_bg = ras2_hw_scrub_set_enabled_bg, + .get_enabled_od = ras2_hw_scrub_get_enabled_od, + .set_enabled_od = ras2_hw_scrub_set_enabled_od, + .get_name = ras2_hw_scrub_get_name, + .cycle_in_hours_range = ras2_hw_scrub_read_schrs_range, + .cycle_in_hours_read = ras2_hw_scrub_read_schrs, + .cycle_in_hours_write = ras2_hw_scrub_write_schrs, +}; + +static DEFINE_IDA(ras2_ida); + +static void ida_release(void *ctx) +{ + struct ras2_scrub_ctx *ras2_ctx = ctx; + + ida_free(&ras2_ida, ras2_ctx->id); +} + +static int ras2_probe(struct platform_device *pdev) +{ + struct edac_ras_feature ras_features[RAS2_DEV_NUM_RAS_FEATURES]; + char scrub_name[RAS2_SCRUB_NAME_LEN]; + struct ras2_scrub_ctx *ras2_ctx; + int num_ras_features = 0; + int ret, id; + + /* RAS2 PCC Channel and Scrub specific context */ + ras2_ctx = devm_kzalloc(&pdev->dev, sizeof(*ras2_ctx), GFP_KERNEL); + if (!ras2_ctx) + return -ENOMEM; + + ras2_ctx->dev = &pdev->dev; + mutex_init(&ras2_ctx->lock); + + ret = devm_ras2_register_pcc_channel(&pdev->dev, ras2_ctx, + *((int *)dev_get_platdata(&pdev->dev))); + if (ret < 0) { + dev_dbg(ras2_ctx->dev, + "failed to register pcc channel ret=%d\n", ret); + return ret; + } + if (!ras2_is_patrol_scrub_support(ras2_ctx)) + return -EOPNOTSUPP; + + ret = ras2_update_patrol_scrub_params_cache(ras2_ctx); + if (ret) + return ret; + + id = ida_alloc(&ras2_ida, GFP_KERNEL); + if (id < 0) + return id; + + ras2_ctx->id = id; + + ret = devm_add_action_or_reset(&pdev->dev, ida_release, ras2_ctx); + if (ret < 0) + return ret; + + snprintf(scrub_name, sizeof(scrub_name), "acpi_ras2_mem%d", + ras2_ctx->id); + + ras_features[num_ras_features].feat = ras_feat_scrub; + ras_features[num_ras_features].scrub_ops = &ras2_scrub_ops; + ras_features[num_ras_features].scrub_ctx = ras2_ctx; + num_ras_features++; + + return edac_ras_dev_register(&pdev->dev, scrub_name, NULL, + num_ras_features, ras_features); +} + +static const struct platform_device_id ras2_id_table[] = { + { .name = "acpi_ras2", }, + { } +}; +MODULE_DEVICE_TABLE(platform, ras2_id_table); + +static struct platform_driver ras2_driver = { + .probe = ras2_probe, + .driver = { + .name = "acpi_ras2", + }, + .id_table = ras2_id_table, +}; +module_driver(ras2_driver, platform_driver_register, platform_driver_unregister); + +MODULE_IMPORT_NS(ACPI_RAS2); +MODULE_DESCRIPTION("ACPI RAS2 memory driver"); +MODULE_LICENSE("GPL");