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 */