From patchwork Thu Feb 20 10:49:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Jain X-Patchwork-Id: 11393843 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 24D0D1395 for ; Thu, 20 Feb 2020 10:51:23 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0C58E2071E for ; Thu, 20 Feb 2020 10:51:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C58E2071E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2F9E710FC35B6; Thu, 20 Feb 2020 02:52:15 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=vaibhav@linux.ibm.com; receiver= Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4518F10FC35B0 for ; Thu, 20 Feb 2020 02:50:48 -0800 (PST) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01KAnMeE087336 for ; Thu, 20 Feb 2020 05:49:55 -0500 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2y8ucmxmhj-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 20 Feb 2020 05:49:55 -0500 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 20 Feb 2020 10:49:53 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 20 Feb 2020 10:49:50 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 01KAnnKq35979280 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Feb 2020 10:49:49 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F40B8A4051; Thu, 20 Feb 2020 10:49:48 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4E76CA4040; Thu, 20 Feb 2020 10:49:46 +0000 (GMT) Received: from vajain21.in.ibm.com.com (unknown [9.199.53.128]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 20 Feb 2020 10:49:46 +0000 (GMT) From: Vaibhav Jain To: linux-nvdimm@lists.01.org Subject: [ndctl PATCH 1/8] libndctl: Refactor out add_dimm() to handle NFIT specific init Date: Thu, 20 Feb 2020 16:19:21 +0530 X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200220104928.198625-1-vaibhav@linux.ibm.com> References: <20200220104928.198625-1-vaibhav@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 20022010-4275-0000-0000-000003A3BEFC X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20022010-4276-0000-0000-000038B7CB48 Message-Id: <20200220104928.198625-2-vaibhav@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-20_03:2020-02-19,2020-02-20 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 adultscore=0 impostorscore=0 spamscore=0 phishscore=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 suspectscore=3 bulkscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002200079 Message-ID-Hash: QOVCCJ5OOT4XEMV4FG3DC4LODWBZMAM4 X-Message-ID-Hash: QOVCCJ5OOT4XEMV4FG3DC4LODWBZMAM4 X-MailFrom: vaibhav@linux.ibm.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: Vaibhav Jain , "Aneesh Kumar K . V" , Alastair D'Silva X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Presently add_dimm() only probes dimms that support NFIT/ACPI. Hence this patch refactors this functionality into two functions namely add_dimm() and add_nfit_dimm(). Function add_dimm() performs allocation and common 'struct ndctl_dimm' initialization and depending on whether the dimm-bus supports NIFT, calls add_nfit_dimm(). Once the probe is completed based on the value of 'ndctl_dimm.cmd_family' appropriate dimm-ops are assigned to the dimm. In case dimm-bus is of unknown type or doesn't support NFIT the initialization still continues, with no dimm-ops assigned to the 'struct ndctl_dimm' there-by limiting the functionality available. This patch shouldn't introduce any behavioral change. Signed-off-by: Vaibhav Jain --- ndctl/lib/libndctl.c | 193 +++++++++++++++++++++++++------------------ 1 file changed, 112 insertions(+), 81 deletions(-) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index d6a28002e7d6..38ddfea6dbc0 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -1401,82 +1401,15 @@ static int ndctl_bind(struct ndctl_ctx *ctx, struct kmod_module *module, static int ndctl_unbind(struct ndctl_ctx *ctx, const char *devpath); static struct kmod_module *to_module(struct ndctl_ctx *ctx, const char *alias); -static void *add_dimm(void *parent, int id, const char *dimm_base) +static int add_nfit_dimm(struct ndctl_dimm *dimm, const char *dimm_base) { - int formats, i; - struct ndctl_dimm *dimm; + int i, rc = -1; char buf[SYSFS_ATTR_SIZE]; - struct ndctl_bus *bus = parent; - struct ndctl_ctx *ctx = bus->ctx; + struct ndctl_ctx *ctx = dimm->bus->ctx; char *path = calloc(1, strlen(dimm_base) + 100); if (!path) - return NULL; - - sprintf(path, "%s/nfit/formats", dimm_base); - if (sysfs_read_attr(ctx, path, buf) < 0) - formats = 1; - else - formats = clamp(strtoul(buf, NULL, 0), 1UL, 2UL); - - dimm = calloc(1, sizeof(*dimm) + sizeof(int) * formats); - if (!dimm) - goto err_dimm; - dimm->bus = bus; - dimm->id = id; - - sprintf(path, "%s/dev", dimm_base); - if (sysfs_read_attr(ctx, path, buf) < 0) - goto err_read; - if (sscanf(buf, "%d:%d", &dimm->major, &dimm->minor) != 2) - goto err_read; - - sprintf(path, "%s/commands", dimm_base); - if (sysfs_read_attr(ctx, path, buf) < 0) - goto err_read; - dimm->cmd_mask = parse_commands(buf, 1); - - dimm->dimm_buf = calloc(1, strlen(dimm_base) + 50); - if (!dimm->dimm_buf) - goto err_read; - dimm->buf_len = strlen(dimm_base) + 50; - - dimm->dimm_path = strdup(dimm_base); - if (!dimm->dimm_path) - goto err_read; - - sprintf(path, "%s/modalias", dimm_base); - if (sysfs_read_attr(ctx, path, buf) < 0) - goto err_read; - dimm->module = to_module(ctx, buf); - - dimm->handle = -1; - dimm->phys_id = -1; - dimm->serial = -1; - dimm->vendor_id = -1; - dimm->device_id = -1; - dimm->revision_id = -1; - dimm->health_eventfd = -1; - dimm->dirty_shutdown = -ENOENT; - dimm->subsystem_vendor_id = -1; - dimm->subsystem_device_id = -1; - dimm->subsystem_revision_id = -1; - dimm->manufacturing_date = -1; - dimm->manufacturing_location = -1; - dimm->cmd_family = -1; - dimm->nfit_dsm_mask = ULONG_MAX; - for (i = 0; i < formats; i++) - dimm->format[i] = -1; - - sprintf(path, "%s/flags", dimm_base); - if (sysfs_read_attr(ctx, path, buf) < 0) { - dimm->locked = -1; - dimm->aliased = -1; - } else - parse_dimm_flags(dimm, buf); - - if (!ndctl_bus_has_nfit(bus)) - goto out; + return -1; /* * 'unique_id' may not be available on older kernels, so don't @@ -1542,24 +1475,15 @@ static void *add_dimm(void *parent, int id, const char *dimm_base) sprintf(path, "%s/nfit/family", dimm_base); if (sysfs_read_attr(ctx, path, buf) == 0) dimm->cmd_family = strtoul(buf, NULL, 0); - if (dimm->cmd_family == NVDIMM_FAMILY_INTEL) - dimm->ops = intel_dimm_ops; - if (dimm->cmd_family == NVDIMM_FAMILY_HPE1) - dimm->ops = hpe1_dimm_ops; - if (dimm->cmd_family == NVDIMM_FAMILY_MSFT) - dimm->ops = msft_dimm_ops; - if (dimm->cmd_family == NVDIMM_FAMILY_HYPERV) - dimm->ops = hyperv_dimm_ops; sprintf(path, "%s/nfit/dsm_mask", dimm_base); if (sysfs_read_attr(ctx, path, buf) == 0) dimm->nfit_dsm_mask = strtoul(buf, NULL, 0); - dimm->formats = formats; sprintf(path, "%s/nfit/format", dimm_base); if (sysfs_read_attr(ctx, path, buf) == 0) dimm->format[0] = strtoul(buf, NULL, 0); - for (i = 1; i < formats; i++) { + for (i = 1; i < dimm->formats; i++) { sprintf(path, "%s/nfit/format%d", dimm_base, i); if (sysfs_read_attr(ctx, path, buf) == 0) dimm->format[i] = strtoul(buf, NULL, 0); @@ -1570,7 +1494,114 @@ static void *add_dimm(void *parent, int id, const char *dimm_base) parse_nfit_mem_flags(dimm, buf); dimm->health_eventfd = open(path, O_RDONLY|O_CLOEXEC); + rc = 0; + err_read: + + free(path); + return rc; +} + +static void *add_dimm(void *parent, int id, const char *dimm_base) +{ + int formats, i, rc = -ENODEV; + struct ndctl_dimm *dimm = NULL; + char buf[SYSFS_ATTR_SIZE]; + struct ndctl_bus *bus = parent; + struct ndctl_ctx *ctx = bus->ctx; + char *path = calloc(1, strlen(dimm_base) + 100); + + if (!path) + return NULL; + + sprintf(path, "%s/nfit/formats", dimm_base); + if (sysfs_read_attr(ctx, path, buf) < 0) + formats = 1; + else + formats = clamp(strtoul(buf, NULL, 0), 1UL, 2UL); + + dimm = calloc(1, sizeof(*dimm) + sizeof(int) * formats); + if (!dimm) + goto err_dimm; + dimm->bus = bus; + dimm->id = id; + + sprintf(path, "%s/dev", dimm_base); + if (sysfs_read_attr(ctx, path, buf) < 0) + goto err_read; + if (sscanf(buf, "%d:%d", &dimm->major, &dimm->minor) != 2) + goto err_read; + + sprintf(path, "%s/commands", dimm_base); + if (sysfs_read_attr(ctx, path, buf) < 0) + goto err_read; + dimm->cmd_mask = parse_commands(buf, 1); + + dimm->dimm_buf = calloc(1, strlen(dimm_base) + 50); + if (!dimm->dimm_buf) + goto err_read; + dimm->buf_len = strlen(dimm_base) + 50; + + dimm->dimm_path = strdup(dimm_base); + if (!dimm->dimm_path) + goto err_read; + + sprintf(path, "%s/modalias", dimm_base); + if (sysfs_read_attr(ctx, path, buf) < 0) + goto err_read; + dimm->module = to_module(ctx, buf); + + dimm->handle = -1; + dimm->phys_id = -1; + dimm->serial = -1; + dimm->vendor_id = -1; + dimm->device_id = -1; + dimm->revision_id = -1; + dimm->health_eventfd = -1; + dimm->dirty_shutdown = -ENOENT; + dimm->subsystem_vendor_id = -1; + dimm->subsystem_device_id = -1; + dimm->subsystem_revision_id = -1; + dimm->manufacturing_date = -1; + dimm->manufacturing_location = -1; + dimm->cmd_family = -1; + dimm->nfit_dsm_mask = ULONG_MAX; + for (i = 0; i < formats; i++) + dimm->format[i] = -1; + + sprintf(path, "%s/flags", dimm_base); + if (sysfs_read_attr(ctx, path, buf) < 0) { + dimm->locked = -1; + dimm->aliased = -1; + } else + parse_dimm_flags(dimm, buf); + + /* Check if the given dimm supports nfit */ + if (ndctl_bus_has_nfit(bus)) { + dimm->formats = formats; + rc = add_nfit_dimm(dimm, dimm_base); + } + + if (rc == -ENODEV) { + /* Unprobed dimm with no family */ + rc = 0; + goto out; + } + + /* Assign dimm-ops based on command family */ + if (dimm->cmd_family == NVDIMM_FAMILY_INTEL) + dimm->ops = intel_dimm_ops; + if (dimm->cmd_family == NVDIMM_FAMILY_HPE1) + dimm->ops = hpe1_dimm_ops; + if (dimm->cmd_family == NVDIMM_FAMILY_MSFT) + dimm->ops = msft_dimm_ops; + if (dimm->cmd_family == NVDIMM_FAMILY_HYPERV) + dimm->ops = hyperv_dimm_ops; out: + if (rc) { + err(ctx, "Unable to probe dimm:%d. Err:%d\n", id, rc); + goto err_read; + } + list_add(&bus->dimms, &dimm->list); free(path); From patchwork Thu Feb 20 10:49:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Jain X-Patchwork-Id: 11393845 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D2ED109A for ; Thu, 20 Feb 2020 10:51:59 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 348CC24656 for ; Thu, 20 Feb 2020 10:51:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 348CC24656 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5418810FC35B8; Thu, 20 Feb 2020 02:52:51 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=vaibhav@linux.ibm.com; receiver= Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D18B310FC35B0 for ; Thu, 20 Feb 2020 02:50:50 -0800 (PST) Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01KAnYEj021110 for ; Thu, 20 Feb 2020 05:49:57 -0500 Received: from e06smtp02.uk.ibm.com (e06smtp02.uk.ibm.com [195.75.94.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 2y8ubv29st-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 20 Feb 2020 05:49:57 -0500 Received: from localhost by e06smtp02.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 20 Feb 2020 10:49:55 -0000 Received: from b06avi18878370.portsmouth.uk.ibm.com (9.149.26.194) by e06smtp02.uk.ibm.com (192.168.101.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 20 Feb 2020 10:49:54 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 01KAnqMP40042980 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Feb 2020 10:49:52 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C73BAA404D; Thu, 20 Feb 2020 10:49:52 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BCD8DA4040; Thu, 20 Feb 2020 10:49:49 +0000 (GMT) Received: from vajain21.in.ibm.com.com (unknown [9.199.53.128]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 20 Feb 2020 10:49:49 +0000 (GMT) From: Vaibhav Jain To: linux-nvdimm@lists.01.org Subject: [ndctl PATCH 2/8] libndctl: Introduce a new dimm-ops dimm_init() & dimm_uninit() Date: Thu, 20 Feb 2020 16:19:22 +0530 X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200220104928.198625-1-vaibhav@linux.ibm.com> References: <20200220104928.198625-1-vaibhav@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 20022010-0008-0000-0000-00000354B665 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20022010-0009-0000-0000-00004A75C5EB Message-Id: <20200220104928.198625-3-vaibhav@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-20_03:2020-02-19,2020-02-20 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 spamscore=0 priorityscore=1501 mlxlogscore=853 bulkscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 adultscore=0 mlxscore=0 suspectscore=3 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002200080 Message-ID-Hash: RHDUOJA5GKOVETKIW4G4R2QIIESXFCAA X-Message-ID-Hash: RHDUOJA5GKOVETKIW4G4R2QIIESXFCAA X-MailFrom: vaibhav@linux.ibm.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: Vaibhav Jain , "Aneesh Kumar K . V" , Alastair D'Silva X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: There are scenarios when a dimm-provider need to allocate some per-dimm data that can be quickly retrieved. This data can be used to cache data that spans multiple 'struct ndctl_cmd' submissions. Unfortunately currently in libnvdimm there is no easiy way to implement this. Even if this data is some how store in an overloaded field of 'struct ndctl_dimm', managing its lifetime is a challenge. To solve this problem this patch proposes a new member 'struct ndctl_dimm.dimm_user_data' to store per-dimm data thats specific to a dimm-provider. Also two new dimm-ops namely dimm_init() & dimm_uninit() are introduced that can be used to manage the lifetime of this per-dimm data. Semantics ========= int (*dimm_init)(struct ndctl_dimm *): This callback will be called just after dimm-probe inside add_dimm() is completed. Dimm-providers should use this callback to allocate per-dimm data and assign it to 'struct ndctl_dimm.dimm_user_data' member. In case this function returns an error, dimm initialization is halted and errors out. void (*dimm_uninit)(struct ndctl_dimm *): This callback will be called during free_dimm() and is only called if previous call to 'dimm_ops->dimm_init()' had reported no error. Dimm-providers should use this callback to unallocate and cleanup 'dimm_user_data'. Signed-off-by: Vaibhav Jain --- ndctl/lib/libndctl.c | 13 ++++++++++++- ndctl/lib/private.h | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index 38ddfea6dbc0..a5f5fdac9f48 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -596,6 +596,10 @@ static void free_dimm(struct ndctl_dimm *dimm) { if (!dimm) return; + /* If needed call the dimm uninitialization function */ + if (dimm->ops && dimm->ops->dimm_uninit) + dimm->ops->dimm_uninit(dimm); + free(dimm->unique_id); free(dimm->dimm_buf); free(dimm->dimm_path); @@ -1596,8 +1600,15 @@ static void *add_dimm(void *parent, int id, const char *dimm_base) dimm->ops = msft_dimm_ops; if (dimm->cmd_family == NVDIMM_FAMILY_HYPERV) dimm->ops = hyperv_dimm_ops; - out: + + /* Call the dimm initialization function if needed */ + if (!rc && dimm->ops && dimm->ops->dimm_init) + rc = dimm->ops->dimm_init(dimm); + +out: if (rc) { + /* Ensure dimm_uninit() is not called during free_dimm() */ + dimm->ops = NULL; err(ctx, "Unable to probe dimm:%d. Err:%d\n", id, rc); goto err_read; } diff --git a/ndctl/lib/private.h b/ndctl/lib/private.h index 1f6a01c55377..fb7fa47f1f37 100644 --- a/ndctl/lib/private.h +++ b/ndctl/lib/private.h @@ -98,6 +98,7 @@ struct ndctl_dimm { } flags; int locked; int aliased; + void *dimm_user_data; struct list_node list; int formats; int format[0]; @@ -340,6 +341,10 @@ struct ndctl_dimm_ops { struct ndctl_cmd *(*new_ack_shutdown_count)(struct ndctl_dimm *); int (*fw_update_supported)(struct ndctl_dimm *); int (*xlat_firmware_status)(struct ndctl_cmd *); + /* Called just after dimm is initialized and probed */ + int (*dimm_init)(struct ndctl_dimm *); + /* Called just before struct ndctl_dimm is de-allocated */ + void (*dimm_uninit)(struct ndctl_dimm *); }; struct ndctl_dimm_ops * const intel_dimm_ops; From patchwork Thu Feb 20 10:49:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Jain X-Patchwork-Id: 11393853 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D8D211395 for ; Thu, 20 Feb 2020 10:52:48 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C15512465D for ; Thu, 20 Feb 2020 10:52:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C15512465D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id DD09E10FC3603; Thu, 20 Feb 2020 02:53:40 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=vaibhav@linux.ibm.com; receiver= Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2C0B010097E1D for ; Thu, 20 Feb 2020 02:51:25 -0800 (PST) Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01KAoW4c190795 for ; Thu, 20 Feb 2020 05:50:32 -0500 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2y92xe8fk9-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 20 Feb 2020 05:50:30 -0500 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 20 Feb 2020 10:50:00 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 20 Feb 2020 10:49:57 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 01KAnuYu31785048 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Feb 2020 10:49:56 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1AE00A404D; Thu, 20 Feb 2020 10:49:56 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 45A7DA4051; Thu, 20 Feb 2020 10:49:53 +0000 (GMT) Received: from vajain21.in.ibm.com.com (unknown [9.199.53.128]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 20 Feb 2020 10:49:53 +0000 (GMT) From: Vaibhav Jain To: linux-nvdimm@lists.01.org Subject: [ndctl PATCH 3/8] libncdtl: Add initial support for NVDIMM_FAMILY_PAPR_SCM dimm family Date: Thu, 20 Feb 2020 16:19:23 +0530 X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200220104928.198625-1-vaibhav@linux.ibm.com> References: <20200220104928.198625-1-vaibhav@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 20022010-0012-0000-0000-0000038891B6 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20022010-0013-0000-0000-000021C52814 Message-Id: <20200220104928.198625-4-vaibhav@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-20_03:2020-02-19,2020-02-20 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 adultscore=0 clxscore=1015 lowpriorityscore=0 phishscore=0 bulkscore=0 spamscore=0 suspectscore=0 malwarescore=0 priorityscore=1501 impostorscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002200079 Message-ID-Hash: OWZGXKLKWLFXB76A2PUWOPTKLM2RZJD7 X-Message-ID-Hash: OWZGXKLKWLFXB76A2PUWOPTKLM2RZJD7 X-MailFrom: vaibhav@linux.ibm.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: Vaibhav Jain , "Aneesh Kumar K . V" , Alastair D'Silva X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: The patch-set adds necessary scaffolding in libndctl for dimms that support papr_scm specification[1]. Since there can be platforms that support Open-Firmware[2] but not the papr_scm specification, hence the changes proposed first add support for probing if the dimm bus supports Open-Firmware. This is done via querying for sysfs attribute 'of_node' in dimm device sysfs directory. If available newly introduced member 'struct ndctl_bus.has_of_node' is set. During the probe of the dimm and execution of add_dimm(), the newly introduced add_of_pmem_dimm() is called if dimm bus reports supports Open-Firmware. Function add_of_pmem_dimm() queries the 'compatible' device tree attribute and based on its value assign NVDIMM_FAMILY_PAPR_SCM to the dimm command family. In future based on the contents of 'compatible' attribute more of_pmem dimm families can be queried. Presently the dimm-ops implementation for NVDIMM_FAMILY_PAPR_SCM is available in global variable 'papr_scm_dimm_ops' which is a NULL pointer. Subsequent patches will provide a working dimm-ops implementation pointed to by 'papr_scm_dimm_ops'. References: [1] : https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git/commit/?id=58b278f568f0509497e2df7310bfd719156a60d1 [2] : https://en.wikipedia.org/wiki/Open_Firmware Signed-off-by: Vaibhav Jain --- ndctl/lib/libndctl.c | 42 ++++++++++++++++++++++++++++++++++++++++++ ndctl/lib/private.h | 2 ++ ndctl/libndctl.h | 1 + ndctl/ndctl.h | 1 + 4 files changed, 46 insertions(+) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index a5f5fdac9f48..650406d27512 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -858,6 +858,12 @@ static void *add_bus(void *parent, int id, const char *ctl_base) bus->revision = strtoul(buf, NULL, 0); } + sprintf(path, "%s/device/of_node/compatible", ctl_base); + if (sysfs_read_attr(ctx, path, buf) < 0) + bus->has_of_node = 0; + else + bus->has_of_node = 1; + sprintf(path, "%s/device/nfit/dsm_mask", ctl_base); if (sysfs_read_attr(ctx, path, buf) < 0) bus->nfit_dsm_mask = 0; @@ -966,6 +972,10 @@ NDCTL_EXPORT int ndctl_bus_has_nfit(struct ndctl_bus *bus) return bus->has_nfit; } +NDCTL_EXPORT int ndctl_bus_has_of_node(struct ndctl_bus *bus) +{ + return bus->has_of_node; +} /** * ndctl_bus_get_major - nd bus character device major number * @bus: ndctl_bus instance returned from ndctl_bus_get_{first|next} @@ -1405,6 +1415,34 @@ static int ndctl_bind(struct ndctl_ctx *ctx, struct kmod_module *module, static int ndctl_unbind(struct ndctl_ctx *ctx, const char *devpath); static struct kmod_module *to_module(struct ndctl_ctx *ctx, const char *alias); +static int add_of_pmem_dimm(struct ndctl_dimm *dimm, const char *dimm_base) +{ + int rc = -ENODEV; + char buf[SYSFS_ATTR_SIZE]; + struct ndctl_ctx *ctx = dimm->bus->ctx; + char *path = calloc(1, strlen(dimm_base) + 100); + + dbg(ctx, "Probing of_pmem dimm %d at %s\n", dimm->id, dimm_base); + + if (!path) + return -ENOMEM; + + sprintf(path, "%s/../of_node/compatible", dimm_base); + if (sysfs_read_attr(ctx, path, buf) < 0) + goto out; + + + dbg(ctx, "Compatible of_pmem dimm %d at %s\n", dimm->id, buf); + if (strcmp(buf, "ibm,pmemory") == 0) { + dimm->cmd_family = NVDIMM_FAMILY_PAPR_SCM; + rc = 0; + goto out; + } +out: + free(path); + return rc; +} + static int add_nfit_dimm(struct ndctl_dimm *dimm, const char *dimm_base) { int i, rc = -1; @@ -1583,6 +1621,8 @@ static void *add_dimm(void *parent, int id, const char *dimm_base) if (ndctl_bus_has_nfit(bus)) { dimm->formats = formats; rc = add_nfit_dimm(dimm, dimm_base); + } else if (ndctl_bus_has_of_node(bus)) { + rc = add_of_pmem_dimm(dimm, dimm_base); } if (rc == -ENODEV) { @@ -1600,6 +1640,8 @@ static void *add_dimm(void *parent, int id, const char *dimm_base) dimm->ops = msft_dimm_ops; if (dimm->cmd_family == NVDIMM_FAMILY_HYPERV) dimm->ops = hyperv_dimm_ops; + if (dimm->cmd_family == NVDIMM_FAMILY_PAPR_SCM) + dimm->ops = papr_scm_dimm_ops; /* Call the dimm initialization function if needed */ if (!rc && dimm->ops && dimm->ops->dimm_init) diff --git a/ndctl/lib/private.h b/ndctl/lib/private.h index fb7fa47f1f37..16754eda7634 100644 --- a/ndctl/lib/private.h +++ b/ndctl/lib/private.h @@ -167,6 +167,7 @@ struct ndctl_bus { int dimms_init; int regions_init; int has_nfit; + int has_of_node; char *bus_path; char *bus_buf; size_t buf_len; @@ -351,6 +352,7 @@ struct ndctl_dimm_ops * const intel_dimm_ops; struct ndctl_dimm_ops * const hpe1_dimm_ops; struct ndctl_dimm_ops * const msft_dimm_ops; struct ndctl_dimm_ops * const hyperv_dimm_ops; +struct ndctl_dimm_ops * const papr_scm_dimm_ops; static inline struct ndctl_bus *cmd_to_bus(struct ndctl_cmd *cmd) { diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h index 9a53049e7f61..32202654885a 100644 --- a/ndctl/libndctl.h +++ b/ndctl/libndctl.h @@ -119,6 +119,7 @@ struct ndctl_bus *ndctl_bus_get_next(struct ndctl_bus *bus); bus = ndctl_bus_get_next(bus)) struct ndctl_ctx *ndctl_bus_get_ctx(struct ndctl_bus *bus); int ndctl_bus_has_nfit(struct ndctl_bus *bus); +int ndctl_bus_has_of_node(struct ndctl_bus *bus); unsigned int ndctl_bus_get_major(struct ndctl_bus *bus); unsigned int ndctl_bus_get_minor(struct ndctl_bus *bus); const char *ndctl_bus_get_devname(struct ndctl_bus *bus); diff --git a/ndctl/ndctl.h b/ndctl/ndctl.h index 008f81cdeb9f..426708e1fd9b 100644 --- a/ndctl/ndctl.h +++ b/ndctl/ndctl.h @@ -263,6 +263,7 @@ struct nd_cmd_pkg { #define NVDIMM_FAMILY_HPE2 2 #define NVDIMM_FAMILY_MSFT 3 #define NVDIMM_FAMILY_HYPERV 4 +#define NVDIMM_FAMILY_PAPR_SCM 5 #define ND_IOCTL_CALL _IOWR(ND_IOCTL, ND_CMD_CALL,\ struct nd_cmd_pkg) From patchwork Thu Feb 20 10:49:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Jain X-Patchwork-Id: 11393855 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DDFFB1395 for ; Thu, 20 Feb 2020 10:53:00 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C67E824656 for ; Thu, 20 Feb 2020 10:53:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C67E824656 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0077F10FC3602; Thu, 20 Feb 2020 02:53:53 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=vaibhav@linux.ibm.com; receiver= Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 6D0B810FC35B2 for ; Thu, 20 Feb 2020 02:51:39 -0800 (PST) Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01KAoW5D190795 for ; Thu, 20 Feb 2020 05:50:46 -0500 Received: from e06smtp02.uk.ibm.com (e06smtp02.uk.ibm.com [195.75.94.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 2y92xe8fmx-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 20 Feb 2020 05:50:44 -0500 Received: from localhost by e06smtp02.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 20 Feb 2020 10:50:03 -0000 Received: from b06avi18878370.portsmouth.uk.ibm.com (9.149.26.194) by e06smtp02.uk.ibm.com (192.168.101.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 20 Feb 2020 10:50:00 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 01KAnxEh26477016 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Feb 2020 10:49:59 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1D38CA404D; Thu, 20 Feb 2020 10:49:59 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9AA31A4051; Thu, 20 Feb 2020 10:49:56 +0000 (GMT) Received: from vajain21.in.ibm.com.com (unknown [9.199.53.128]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 20 Feb 2020 10:49:56 +0000 (GMT) From: Vaibhav Jain To: linux-nvdimm@lists.01.org Subject: [ndctl PATCH 4/8] libndctl: Add support for parsing of_pmem dimm flags and monitor mode Date: Thu, 20 Feb 2020 16:19:24 +0530 X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200220104928.198625-1-vaibhav@linux.ibm.com> References: <20200220104928.198625-1-vaibhav@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 20022010-0008-0000-0000-00000354B673 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20022010-0009-0000-0000-00004A75C5F7 Message-Id: <20200220104928.198625-5-vaibhav@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-20_03:2020-02-19,2020-02-20 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 adultscore=0 clxscore=1015 lowpriorityscore=0 phishscore=0 bulkscore=0 spamscore=0 suspectscore=3 malwarescore=0 priorityscore=1501 impostorscore=0 mlxlogscore=976 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002200079 Message-ID-Hash: DVTUD3KYT3XDDPAA7AASH42Y4UVVOZG5 X-Message-ID-Hash: DVTUD3KYT3XDDPAA7AASH42Y4UVVOZG5 X-MailFrom: vaibhav@linux.ibm.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: Vaibhav Jain , "Aneesh Kumar K . V" , Alastair D'Silva X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Add support for parsing the dimm flags for of_pmem supporting dimms. The flag file is exported in sysfs as 'papr_flags' and its contents are space separated flags indicating the current state of the dimm. A newly introduced function parse_of_pmem_flags() reads the contents of this flag file and sets appropriate flag bits in 'struct ndctl_dimm.flags'. This function is called at the end of of_pmem probe function add_of_pmem_dimm(). Also we advertise support for monitor mode by allocating a file descriptor to the 'papr_flags' file and assigning it to 'struct ndctl_dimm.health_event_fd'. Signed-off-by: Vaibhav Jain --- ndctl/lib/libndctl.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index 650406d27512..7cc50afac404 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -801,6 +801,28 @@ static void parse_nfit_mem_flags(struct ndctl_dimm *dimm, char *flags) ndctl_dimm_get_devname(dimm), flags); } +static void parse_of_pmem_flags(struct ndctl_dimm *dimm, char *flags) +{ + char *start, *end; + + start = flags; + while ((end = strchr(start, ' '))) { + *end = '\0'; + if (strcmp(start, "not_armed") == 0) + dimm->flags.f_arm = 1; + else if (strcmp(start, "save_fail") == 0) + dimm->flags.f_save = 1; + else if (strcmp(start, "flush_fail") == 0) + dimm->flags.f_flush = 1; + else if (strcmp(start, "smart_notify") == 0) + dimm->flags.f_notify = 1; + start = end + 1; + } + if (end != start) + dbg(ndctl_dimm_get_ctx(dimm), "%s: %s\n", + ndctl_dimm_get_devname(dimm), flags); +} + static void parse_dimm_flags(struct ndctl_dimm *dimm, char *flags) { char *start, *end; @@ -1436,8 +1458,17 @@ static int add_of_pmem_dimm(struct ndctl_dimm *dimm, const char *dimm_base) if (strcmp(buf, "ibm,pmemory") == 0) { dimm->cmd_family = NVDIMM_FAMILY_PAPR_SCM; rc = 0; - goto out; + goto out_monitor; } + +out_monitor: + /* read the flags and also allocate the monitor mode event_fd */ + sprintf(path, "%s/papr_flags", dimm_base); + if (sysfs_read_attr(ctx, path, buf) == 0) + parse_of_pmem_flags(dimm, buf); + + /* Allocate monitor mode fd */ + dimm->health_eventfd = open(path, O_RDONLY|O_CLOEXEC); out: free(path); return rc; From patchwork Thu Feb 20 10:49:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Jain X-Patchwork-Id: 11393847 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 73335109A for ; Thu, 20 Feb 2020 10:52:12 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5AB1F24656 for ; Thu, 20 Feb 2020 10:52:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5AB1F24656 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7E87610FC35B9; Thu, 20 Feb 2020 02:53:04 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=vaibhav@linux.ibm.com; receiver= Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3B79C10097E1D for ; Thu, 20 Feb 2020 02:51:01 -0800 (PST) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01KAiZ6S118252 for ; Thu, 20 Feb 2020 05:50:08 -0500 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2y8uchpsk4-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 20 Feb 2020 05:50:08 -0500 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 20 Feb 2020 10:50:06 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 20 Feb 2020 10:50:03 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 01KAo2wE12845260 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Feb 2020 10:50:02 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 37CEAA4051; Thu, 20 Feb 2020 10:50:02 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B1E9DA404D; Thu, 20 Feb 2020 10:49:59 +0000 (GMT) Received: from vajain21.in.ibm.com.com (unknown [9.199.53.128]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 20 Feb 2020 10:49:59 +0000 (GMT) From: Vaibhav Jain To: linux-nvdimm@lists.01.org Subject: [ndctl PATCH 5/8] libndctl,papr_scm: Add definitions for PAPR_SCM DSM commands Date: Thu, 20 Feb 2020 16:19:25 +0530 X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200220104928.198625-1-vaibhav@linux.ibm.com> References: <20200220104928.198625-1-vaibhav@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 20022010-4275-0000-0000-000003A3BF12 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20022010-4276-0000-0000-000038B7CB5E Message-Id: <20200220104928.198625-6-vaibhav@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-20_02:2020-02-19,2020-02-20 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=999 lowpriorityscore=0 malwarescore=0 suspectscore=1 adultscore=0 clxscore=1015 impostorscore=0 spamscore=0 priorityscore=1501 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002200079 Message-ID-Hash: J4YLWVTFQJJV6L3HQ5AAEUGUO3C2FR5X X-Message-ID-Hash: J4YLWVTFQJJV6L3HQ5AAEUGUO3C2FR5X X-MailFrom: vaibhav@linux.ibm.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: Vaibhav Jain , "Aneesh Kumar K . V" , Alastair D'Silva X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Pull the kernel definition of PAPR_SCM DSM command which is located in the kernel tree at Ref[1]. Also add an implementation of 'papr_scm_dimm_ops' in a new file named 'papr_scm.c'. For now only an implementation of 'dimm_ops.cmd_is_supported' is provided. References: [1]: arch/powerpc/include/uapi/asm/papr_scm_dsm.h Signed-off-by: Vaibhav Jain --- ndctl/lib/Makefile.am | 1 + ndctl/lib/papr_scm.c | 34 ++++++++++ ndctl/lib/papr_scm_dsm.h | 143 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 178 insertions(+) create mode 100644 ndctl/lib/papr_scm.c create mode 100644 ndctl/lib/papr_scm_dsm.h diff --git a/ndctl/lib/Makefile.am b/ndctl/lib/Makefile.am index e4eb0060bca4..3943541e435d 100644 --- a/ndctl/lib/Makefile.am +++ b/ndctl/lib/Makefile.am @@ -21,6 +21,7 @@ libndctl_la_SOURCES =\ hpe1.c \ msft.c \ hyperv.c \ + papr_scm.c \ ars.c \ firmware.c \ libndctl.c diff --git a/ndctl/lib/papr_scm.c b/ndctl/lib/papr_scm.c new file mode 100644 index 000000000000..878698a5a8b4 --- /dev/null +++ b/ndctl/lib/papr_scm.c @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2020 IBM Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU Lesser General Public License, + * version 2.1, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for + * more details. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static bool papr_cmd_is_supported(struct ndctl_dimm *dimm, int cmd) +{ + /* Handle this separately to support monitor mode */ + if (cmd == ND_CMD_SMART) + return true; + + return !!(dimm->cmd_mask & (1ULL << cmd)); +} + +struct ndctl_dimm_ops * const papr_scm_dimm_ops = &(struct ndctl_dimm_ops) { + .cmd_is_supported = papr_cmd_is_supported, +}; diff --git a/ndctl/lib/papr_scm_dsm.h b/ndctl/lib/papr_scm_dsm.h new file mode 100644 index 000000000000..aacced453579 --- /dev/null +++ b/ndctl/lib/papr_scm_dsm.h @@ -0,0 +1,143 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +/* + * PAPR SCM Device specific methods for libndctl and ndctl + * + * (C) Copyright IBM 2020 + * + * Author: Vaibhav Jain + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef _UAPI_ASM_POWERPC_PAPR_SCM_DSM_H_ +#define _UAPI_ASM_POWERPC_PAPR_SCM_DSM_H_ + +#include + +#ifdef __KERNEL__ +#include +#else +#include +#endif + +/* + * Sub commands for ND_CMD_CALL. To prevent overlap from ND_CMD_*, values for + * these enums start at 0x10000. These values are then returned from + * cmd_to_func() making it easy to implement the switch-case block in + * papr_scm_ndctl() + */ +enum dsm_papr_scm { + DSM_PAPR_SCM_MIN = 0x10000, + DSM_PAPR_SCM_HEALTH, + DSM_PAPR_SCM_STATS, + DSM_PAPR_SCM_MAX, +}; + +enum dsm_papr_scm_dimm_health { + DSM_PAPR_SCM_DIMM_HEALTHY, + DSM_PAPR_SCM_DIMM_UNHEALTHY, + DSM_PAPR_SCM_DIMM_CRITICAL, + DSM_PAPR_SCM_DIMM_FATAL, +}; + +/* Papr-scm-header + payload expected with ND_CMD_CALL ioctl from libnvdimm */ +struct nd_papr_scm_cmd_pkg { + struct nd_cmd_pkg hdr; /* Package header containing sub-cmd */ + int32_t cmd_status; /* Out: Sub-cmd status returned back */ + uint16_t payload_offset; /* In: offset from start of struct */ + uint16_t payload_version; /* In/Out: version of the payload */ + uint8_t payload[]; /* In/Out: Sub-cmd data buffer */ +}; + +/* Helpers to evaluate the size of PAPR_SCM envelope */ +/* Calculate the papr_scm-header size */ +#define ND_PAPR_SCM_ENVELOPE_CONTENT_HDR_SIZE \ + (sizeof(struct nd_papr_scm_cmd_pkg) - sizeof(struct nd_cmd_pkg)) +/* + * Given a type calculate the envelope size + * (nd-header + papr_scm-header + payload) + */ +#define ND_PAPR_SCM_ENVELOPE_SIZE(_type_) \ + (sizeof(_type_) + sizeof(struct nd_papr_scm_cmd_pkg)) + +/* Given a type envelope-content size (papr_scm-header + payload) */ +#define ND_PAPR_SCM_ENVELOPE_CONTENT_SIZE(_type_) \ + (sizeof(_type_) + ND_PAPR_SCM_ENVELOPE_CONTENT_HDR_SIZE) + +/* + * Struct exchanged between kernel & ndctl in for PAPR_DSM_PAPR_SMART_HEALTH + * Various bitflags indicate the health status of the dimm. + */ +struct nd_papr_scm_dimm_health_stat_v1 { + /* Dimm not armed. So contents wont persist */ + bool dimm_unarmed; + /* Previous shutdown did not persist contents */ + bool dimm_bad_shutdown; + /* Contents from previous shutdown werent restored */ + bool dimm_bad_restore; + /* Contents of the dimm have been scrubbed */ + bool dimm_scrubbed; + /* Contents of the dimm cant be modified until CEC reboot */ + bool dimm_locked; + /* Contents of dimm are encrypted */ + bool dimm_encrypted; + + enum dsm_papr_scm_dimm_health dimm_health; +}; + +/* + * Typedef the current struct for dimm_health so that any application + * or kernel recompiled after introducing a new version autometically + * supports the new version. + */ +#define nd_papr_scm_dimm_health_stat nd_papr_scm_dimm_health_stat_v1 + +/* Current version number for the dimm health struct */ +#define ND_PAPR_SCM_DIMM_HEALTH_VERSION 1 + +/* Struct holding a single performance metric */ +struct nd_papr_scm_perf_stat { + u64 statistic_id; + u64 statistic_value; +}; + +/* Struct exchanged between kernel and ndctl reporting drc perf stats */ +struct nd_papr_scm_perf_stats_v1 { + /* Number of stats following */ + u32 num_statistics; + + /* zero or more performance matrics */ + struct nd_papr_scm_perf_stat scm_statistics[]; +}; + +/* + * Typedef the current struct for dimm_stats so that any application + * or kernel recompiled after introducing a new version autometically + * supports the new version. + */ +#define nd_papr_scm_perf_stats nd_papr_scm_perf_stats_v1 +#define ND_PAPR_SCM_DIMM_PERF_STATS_VERSION 1 + +/* Convert a libnvdimm nd_cmd_pkg to papr_scm specific pkg */ +static struct nd_papr_scm_cmd_pkg *nd_to_papr_cmd_pkg(struct nd_cmd_pkg *cmd) +{ + return (struct nd_papr_scm_cmd_pkg *) cmd; +} + +/* Return the payload pointer for a given pcmd */ +static void *papr_scm_pcmd_to_payload(struct nd_papr_scm_cmd_pkg *pcmd) +{ + if (pcmd->hdr.nd_size_in == 0 && pcmd->hdr.nd_size_out == 0) + return NULL; + else + return (void *)((u8 *) pcmd + pcmd->payload_offset); +} +#endif /* _UAPI_ASM_POWERPC_PAPR_SCM_DSM_H_ */ From patchwork Thu Feb 20 10:49:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Jain X-Patchwork-Id: 11393849 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 81EF41395 for ; Thu, 20 Feb 2020 10:52:26 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6923724656 for ; Thu, 20 Feb 2020 10:52:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6923724656 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 96D8010FC35BC; Thu, 20 Feb 2020 02:53:18 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=vaibhav@linux.ibm.com; receiver= Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B4AC610097E1D for ; Thu, 20 Feb 2020 02:51:06 -0800 (PST) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01KAnMFT087334 for ; Thu, 20 Feb 2020 05:50:13 -0500 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2y8ucmxmsa-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 20 Feb 2020 05:50:13 -0500 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 20 Feb 2020 10:50:08 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 20 Feb 2020 10:50:06 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 01KAo5hF39518394 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Feb 2020 10:50:05 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 53029A4040; Thu, 20 Feb 2020 10:50:05 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C3653A4053; Thu, 20 Feb 2020 10:50:02 +0000 (GMT) Received: from vajain21.in.ibm.com.com (unknown [9.199.53.128]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 20 Feb 2020 10:50:02 +0000 (GMT) From: Vaibhav Jain To: linux-nvdimm@lists.01.org Subject: [ndctl PATCH 6/8] libndctl,papr_scm: Implement scaffolding to issue and handle DSM cmds Date: Thu, 20 Feb 2020 16:19:26 +0530 X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200220104928.198625-1-vaibhav@linux.ibm.com> References: <20200220104928.198625-1-vaibhav@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 20022010-0028-0000-0000-000003DCB79B X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20022010-0029-0000-0000-000024A1C737 Message-Id: <20200220104928.198625-7-vaibhav@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-20_03:2020-02-19,2020-02-20 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 adultscore=0 impostorscore=0 spamscore=0 phishscore=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 suspectscore=3 bulkscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002200079 Message-ID-Hash: 3ERGACHWZQBYCOFZBU7POOMSW5HUDLSU X-Message-ID-Hash: 3ERGACHWZQBYCOFZBU7POOMSW5HUDLSU X-MailFrom: vaibhav@linux.ibm.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: Vaibhav Jain , "Aneesh Kumar K . V" , Alastair D'Silva X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: This patch implement necessary infrastructure inside 'papr_scm.c' to issue and handle DSM commands. Changed implemented are: * Implement dimm initialization/un-initialization functions papr_dimm_init()/unint() to allocate a per-dimm 'struct dimm_priv' instance. * New helper function allocate_cmd() to allocate command packages for a specific DSM command and payload size. * New function update_dimm_state() to parse a given command payload and update per dimm 'struct dimm_priv'. * Provide an implementation of 'dimm_ops->smart_get_flags' to send the submitted instance of 'struct ndctl_cmd' to update_dimm_state(). * Logging helpers for papr_scm that use the underlying libndctl provided logging. Signed-off-by: Vaibhav Jain --- ndctl/lib/papr_scm.c | 174 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) diff --git a/ndctl/lib/papr_scm.c b/ndctl/lib/papr_scm.c index 878698a5a8b4..0a3857e2a4c4 100644 --- a/ndctl/lib/papr_scm.c +++ b/ndctl/lib/papr_scm.c @@ -20,6 +20,29 @@ #include #include +/* Utility logging maros for simplify logging */ +#define PAPR_DBG(_dimm_, _format_str_, ...) dbg(_dimm_->bus->ctx, \ + "papr_scm:"#_format_str_, \ + ##__VA_ARGS__) +#define PAPR_INFO(_dimm_, _format_str_, ...) info(_dimm_->bus->ctx, \ + "papr_scm:"#_format_str_, \ + ##__VA_ARGS__) +#define PAPR_ERR(_dimm_, _format_str_, ...) err(_dimm_->bus->ctx, \ + "papr_scm:"#_format_str_, \ + ##__VA_ARGS__) +#define PAPR_NOTICE(_dimm_, _format_str_, ...) notice(_dimm_->bus->ctx, \ + "papr_scm:"#_format_str_, \ + ##__VA_ARGS__) + +/* Command flags to indicate if a given command is parsed of not */ +#define CMD_PKG_SUBMITTED 1 +#define CMD_PKG_PARSED 2 + +/* Per dimm data. Holds per-dimm data parsed from the cmd_pkgs */ +struct dimm_priv { + /* Empty for now */ +}; + static bool papr_cmd_is_supported(struct ndctl_dimm *dimm, int cmd) { /* Handle this separately to support monitor mode */ @@ -29,6 +52,157 @@ static bool papr_cmd_is_supported(struct ndctl_dimm *dimm, int cmd) return !!(dimm->cmd_mask & (1ULL << cmd)); } +static __u64 pcmd_to_dsm(const struct nd_papr_scm_cmd_pkg *pcmd) +{ + return pcmd->hdr.nd_command; +} + +/* Verify if the given command is supported and valid */ +static bool cmd_is_valid(struct ndctl_dimm *dimm, struct ndctl_cmd *cmd) +{ + const struct nd_papr_scm_cmd_pkg *pcmd = nd_to_papr_cmd_pkg(cmd->pkg); + + if (dimm == NULL) + return false; + + if (cmd == NULL) { + PAPR_ERR(dimm, "Invalid command\n"); + return false; + } + + /* Verify the command family */ + if (pcmd->hdr.nd_family != NVDIMM_FAMILY_PAPR_SCM) { + PAPR_ERR(dimm, "Invalid command family:0x%016llx\n", + pcmd->hdr.nd_family); + return false; + } + + /* Verify the DSM */ + if (pcmd_to_dsm(pcmd) <= DSM_PAPR_SCM_MIN || + pcmd_to_dsm(pcmd) >= DSM_PAPR_SCM_MAX) { + PAPR_ERR(dimm, "Invalid command :0x%016llx\n", + pcmd->hdr.nd_command); + return false; + } + + return true; +} + +/* Parse a command payload and update dimm flags/private data */ +static int update_dimm_stats(struct ndctl_dimm *dimm, struct ndctl_cmd *cmd) +{ + const struct nd_papr_scm_cmd_pkg *pcmd; + + if (!cmd_is_valid(dimm, cmd)) + return -EINVAL; + + /* + * Silently prevent parsing of an already parsed ndctl_cmd else + * mark the command as parsed. + */ + if (cmd->status >= CMD_PKG_PARSED) { + return 0; + } else if (cmd->status < 0) { + PAPR_ERR(dimm, "Command error %d\n", cmd->status); + return -ENXIO; + } + + /* Mark the command as parsed */ + cmd->status = CMD_PKG_PARSED; + + /* Get the command dsm and handle it */ + pcmd = nd_to_papr_cmd_pkg(cmd->pkg); + switch (pcmd_to_dsm(pcmd)) { + default: + PAPR_ERR(dimm, "Unhandled dsm-command 0x%016llx\n", + pcmd_to_dsm(pcmd)); + return -ENOENT; + } +} + +/* Allocate a struct ndctl_cmd for given dsm command with payload size */ +static struct ndctl_cmd *allocate_cmd(struct ndctl_dimm *dimm, + __u64 dsm_cmd, size_t payload_size, + uint16_t payload_version) +{ + struct ndctl_cmd *cmd; + struct nd_papr_scm_cmd_pkg *pcmd; + size_t size; + + size = sizeof(struct ndctl_cmd) + + sizeof(struct nd_papr_scm_cmd_pkg) + payload_size; + cmd = calloc(1, size); + if (!cmd) + return NULL; + pcmd = nd_to_papr_cmd_pkg(cmd->pkg); + + ndctl_cmd_ref(cmd); + cmd->dimm = dimm; + cmd->type = ND_CMD_CALL; + cmd->size = size; + cmd->status = CMD_PKG_SUBMITTED; + cmd->firmware_status = (u32 *) &pcmd->cmd_status; + + /* Populate the nd_cmd_pkg contained in nd_papr_scm_cmd_pkg */ + pcmd->hdr.nd_family = NVDIMM_FAMILY_PAPR_SCM; + pcmd->hdr.nd_command = dsm_cmd; + + pcmd->payload_version = payload_version; + pcmd->payload_offset = sizeof(struct nd_papr_scm_cmd_pkg); + + /* Keep payload size empty. To be populated by called */ + pcmd->hdr.nd_fw_size = 0; + pcmd->hdr.nd_size_out = 0; + pcmd->hdr.nd_size_in = 0; + + return cmd; +} + +static unsigned int papr_smart_get_flags(struct ndctl_cmd *cmd) +{ + /* In case of error return empty flags * */ + if (update_dimm_stats(cmd->dimm, cmd)) + return 0; + + /* Return empty flags for now as no DSM support */ + return 0; +} + +static int papr_dimm_init(struct ndctl_dimm *dimm) +{ + struct dimm_priv *p; + + if (dimm->dimm_user_data) { + PAPR_DBG(dimm, "Dimm already initialized !!\n"); + return 0; + } + + p = calloc(1, sizeof(struct dimm_priv)); + if (!p) { + PAPR_ERR(dimm, "Unable to allocate memory for dimm-private\n"); + return -1; + } + + dimm->dimm_user_data = p; + return 0; +} + +static void papr_dimm_uninit(struct ndctl_dimm *dimm) +{ + struct dimm_priv *p = dimm->dimm_user_data; + + if (!p) { + PAPR_DBG(dimm, "Dimm already un-initialized !!\n"); + return; + } + + dimm->dimm_user_data = NULL; + free(p); +} + struct ndctl_dimm_ops * const papr_scm_dimm_ops = &(struct ndctl_dimm_ops) { .cmd_is_supported = papr_cmd_is_supported, + .dimm_init = papr_dimm_init, + .dimm_uninit = papr_dimm_uninit, + .smart_get_flags = papr_smart_get_flags, }; From patchwork Thu Feb 20 10:49:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Jain X-Patchwork-Id: 11393851 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 97FB9109A for ; Thu, 20 Feb 2020 10:52:35 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7FA0124656 for ; Thu, 20 Feb 2020 10:52:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7FA0124656 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id AE35110FC35BD; Thu, 20 Feb 2020 02:53:27 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=vaibhav@linux.ibm.com; receiver= Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id CFD1610097E1D for ; Thu, 20 Feb 2020 02:51:07 -0800 (PST) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01KAiaL2118921 for ; Thu, 20 Feb 2020 05:50:14 -0500 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0a-001b2d01.pphosted.com with ESMTP id 2y8uchpspp-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 20 Feb 2020 05:50:14 -0500 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 20 Feb 2020 10:50:12 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp01.uk.ibm.com (192.168.101.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 20 Feb 2020 10:50:10 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 01KAo8Vb28180524 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Feb 2020 10:50:08 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B0AB1A4055; Thu, 20 Feb 2020 10:50:08 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0F514A404D; Thu, 20 Feb 2020 10:50:06 +0000 (GMT) Received: from vajain21.in.ibm.com.com (unknown [9.199.53.128]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 20 Feb 2020 10:50:05 +0000 (GMT) From: Vaibhav Jain To: linux-nvdimm@lists.01.org Subject: [ndctl PATCH 7/8] libndctl,papr_scm: Implement support for DSM_PAPR_SCM_HEALTH Date: Thu, 20 Feb 2020 16:19:27 +0530 X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200220104928.198625-1-vaibhav@linux.ibm.com> References: <20200220104928.198625-1-vaibhav@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 20022010-4275-0000-0000-000003A3BF14 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20022010-4276-0000-0000-000038B7CB60 Message-Id: <20200220104928.198625-8-vaibhav@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-20_02:2020-02-19,2020-02-20 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=999 lowpriorityscore=0 malwarescore=0 suspectscore=1 adultscore=0 clxscore=1015 impostorscore=0 spamscore=0 priorityscore=1501 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002200079 Message-ID-Hash: CW65DFPK43LJ7OJQZUC7WKSOP3UTPDSQ X-Message-ID-Hash: CW65DFPK43LJ7OJQZUC7WKSOP3UTPDSQ X-MailFrom: vaibhav@linux.ibm.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: Vaibhav Jain , "Aneesh Kumar K . V" , Alastair D'Silva X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Add support for reporting DIMM health by issuing DSM_PAPR_SCM_HEALTH DSM. It returns an instance of ' struct nd_papr_scm_dimm_health_stat' as defined in 'papr_scm_dsm.h'. The patch provides support for dimm-ops 'new_smart' & 'smart_get_health' as papr_new_smart_health() & papr_smart_get_health() respectively. This callbacks should enable ndctl to report DIMM health. Also a new member 'struct dimm_priv.health' is introduced which holds the current health status of the dimm. This member is set inside newly added function 'update_dimm_health_v1()' which parses the v1 payload returned by the kernel after servicing DSM_PAPR_SCM_HEALTH. The function will also update dimm-flags viz 'struct ndctl_dimm.flags.f_*' based on the flags set in the returned payload. Signed-off-by: Vaibhav Jain --- ndctl/lib/papr_scm.c | 80 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/ndctl/lib/papr_scm.c b/ndctl/lib/papr_scm.c index 0a3857e2a4c4..a01649d3a9fe 100644 --- a/ndctl/lib/papr_scm.c +++ b/ndctl/lib/papr_scm.c @@ -40,7 +40,9 @@ /* Per dimm data. Holds per-dimm data parsed from the cmd_pkgs */ struct dimm_priv { - /* Empty for now */ + + /* Cache the dimm health status */ + struct nd_papr_scm_dimm_health_stat health; }; static bool papr_cmd_is_supported(struct ndctl_dimm *dimm, int cmd) @@ -88,6 +90,43 @@ static bool cmd_is_valid(struct ndctl_dimm *dimm, struct ndctl_cmd *cmd) return true; } +/* + * Parse the nd_papr_scm_dimm_health_stat_v1 payload embedded in ndctl_cmd and + * update dimm health/flags + */ +static int update_dimm_health_v1(struct ndctl_dimm *dimm, struct ndctl_cmd *cmd) +{ + struct nd_papr_scm_cmd_pkg *pcmd = nd_to_papr_cmd_pkg(cmd->pkg); + struct dimm_priv *p = dimm->dimm_user_data; + const struct nd_papr_scm_dimm_health_stat_v1 *health = + papr_scm_pcmd_to_payload(pcmd); + + /* Update the dimm flags */ + dimm->flags.f_arm = health->dimm_unarmed; + dimm->flags.f_flush = health->dimm_bad_shutdown; + dimm->flags.f_restore = health->dimm_bad_restore; + dimm->flags.f_smart = (health->dimm_health != 0); + + /* Cache the dimm health information */ + memcpy(&p->health, health, sizeof(*health)); + return 0; +} + +/* Check payload version returned and pass the packet to appropriate handler */ +static int update_dimm_health(struct ndctl_dimm *dimm, struct ndctl_cmd *cmd) +{ + const struct nd_papr_scm_cmd_pkg *pcmd = nd_to_papr_cmd_pkg(cmd->pkg); + + if (pcmd->payload_version == 1) + return update_dimm_health_v1(dimm, cmd); + + /* unknown version */ + PAPR_ERR(dimm, "Unknown payload version for dimm_health." + "Ver=%d, Supported=%d\n", pcmd->payload_version, + ND_PAPR_SCM_DIMM_HEALTH_VERSION); + return -EINVAL; +} + /* Parse a command payload and update dimm flags/private data */ static int update_dimm_stats(struct ndctl_dimm *dimm, struct ndctl_cmd *cmd) { @@ -113,6 +152,8 @@ static int update_dimm_stats(struct ndctl_dimm *dimm, struct ndctl_cmd *cmd) /* Get the command dsm and handle it */ pcmd = nd_to_papr_cmd_pkg(cmd->pkg); switch (pcmd_to_dsm(pcmd)) { + case DSM_PAPR_SCM_HEALTH: + return update_dimm_health(dimm, cmd); default: PAPR_ERR(dimm, "Unhandled dsm-command 0x%016llx\n", pcmd_to_dsm(pcmd)); @@ -158,14 +199,45 @@ static struct ndctl_cmd *allocate_cmd(struct ndctl_dimm *dimm, return cmd; } +static struct ndctl_cmd *papr_new_smart_health(struct ndctl_dimm *dimm) +{ + struct ndctl_cmd *cmd_ret; + + cmd_ret = allocate_cmd(dimm, DSM_PAPR_SCM_HEALTH, + sizeof(struct nd_papr_scm_dimm_health_stat), + ND_PAPR_SCM_DIMM_HEALTH_VERSION); + if (!cmd_ret) { + PAPR_ERR(dimm, "Unable to allocate smart_health command\n"); + return NULL; + } + + cmd_ret->pkg[0].nd_size_out = ND_PAPR_SCM_ENVELOPE_CONTENT_SIZE( + struct nd_papr_scm_dimm_health_stat); + + return cmd_ret; +} + +static unsigned int papr_smart_get_health(struct ndctl_cmd *cmd) +{ + struct dimm_priv *p = cmd->dimm->dimm_user_data; + + /* + * Update the dimm stats and use some math to return one of + * defined ND_SMART_*_HEALTH values + */ + if (update_dimm_stats(cmd->dimm, cmd) || !p->health.dimm_health) + return 0; + else + return 1 << (p->health.dimm_health - 1); +} + static unsigned int papr_smart_get_flags(struct ndctl_cmd *cmd) { /* In case of error return empty flags * */ if (update_dimm_stats(cmd->dimm, cmd)) return 0; - /* Return empty flags for now as no DSM support */ - return 0; + return ND_SMART_HEALTH_VALID; } static int papr_dimm_init(struct ndctl_dimm *dimm) @@ -205,4 +277,6 @@ struct ndctl_dimm_ops * const papr_scm_dimm_ops = &(struct ndctl_dimm_ops) { .dimm_init = papr_dimm_init, .dimm_uninit = papr_dimm_uninit, .smart_get_flags = papr_smart_get_flags, + .new_smart = papr_new_smart_health, + .smart_get_health = papr_smart_get_health, }; From patchwork Thu Feb 20 10:49:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaibhav Jain X-Patchwork-Id: 11393857 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1F563109A for ; Thu, 20 Feb 2020 10:54:40 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 06CA524656 for ; Thu, 20 Feb 2020 10:54:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 06CA524656 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2E44E10FC35BD; Thu, 20 Feb 2020 02:55:32 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=vaibhav@linux.ibm.com; receiver= Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4B06F10FC35BB for ; Thu, 20 Feb 2020 02:54:27 -0800 (PST) Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01KArUgN077483 for ; Thu, 20 Feb 2020 05:53:34 -0500 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0b-001b2d01.pphosted.com with ESMTP id 2y8xdpnq1f-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 20 Feb 2020 05:53:33 -0500 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 20 Feb 2020 10:50:17 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 20 Feb 2020 10:50:13 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 01KAoCsf48038088 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Feb 2020 10:50:12 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2E8E9A4057; Thu, 20 Feb 2020 10:50:12 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5274AA4055; Thu, 20 Feb 2020 10:50:09 +0000 (GMT) Received: from vajain21.in.ibm.com.com (unknown [9.199.53.128]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 20 Feb 2020 10:50:08 +0000 (GMT) From: Vaibhav Jain To: linux-nvdimm@lists.01.org Subject: [ndctl PATCH 8/8] libndctl,papr_scm: Add support for reporting bad shutdown Date: Thu, 20 Feb 2020 16:19:28 +0530 X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200220104928.198625-1-vaibhav@linux.ibm.com> References: <20200220104928.198625-1-vaibhav@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 20022010-0016-0000-0000-000002E88E73 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20022010-0017-0000-0000-0000334BAA54 Message-Id: <20200220104928.198625-9-vaibhav@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-20_03:2020-02-19,2020-02-20 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 impostorscore=0 mlxlogscore=999 mlxscore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 suspectscore=1 clxscore=1015 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002200081 Message-ID-Hash: WE767EVCMAPCPTWIRIIVXSWW2TLEWWVJ X-Message-ID-Hash: WE767EVCMAPCPTWIRIIVXSWW2TLEWWVJ X-MailFrom: vaibhav@linux.ibm.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: Vaibhav Jain , "Aneesh Kumar K . V" , Alastair D'Silva X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Provide support for dimm-op 'smart_get_shutdown_state' implemented as papr_smart_get_shutdown_state() to report a bad shutdown that couldn't flush contents of nvdimm to flash memory properly. Signed-off-by: Vaibhav Jain --- ndctl/lib/papr_scm.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ndctl/lib/papr_scm.c b/ndctl/lib/papr_scm.c index a01649d3a9fe..8a6fec992aff 100644 --- a/ndctl/lib/papr_scm.c +++ b/ndctl/lib/papr_scm.c @@ -231,13 +231,22 @@ static unsigned int papr_smart_get_health(struct ndctl_cmd *cmd) return 1 << (p->health.dimm_health - 1); } +static unsigned int papr_smart_get_shutdown_state(struct ndctl_cmd *cmd) +{ + struct dimm_priv *p = cmd->dimm->dimm_user_data; + + /* Update dimm state and return f_flush */ + return update_dimm_stats(cmd->dimm, cmd) ? + 0 : p->health.dimm_bad_shutdown; +} + static unsigned int papr_smart_get_flags(struct ndctl_cmd *cmd) { /* In case of error return empty flags * */ if (update_dimm_stats(cmd->dimm, cmd)) return 0; - return ND_SMART_HEALTH_VALID; + return ND_SMART_HEALTH_VALID | ND_SMART_SHUTDOWN_VALID; } static int papr_dimm_init(struct ndctl_dimm *dimm) @@ -279,4 +288,5 @@ struct ndctl_dimm_ops * const papr_scm_dimm_ops = &(struct ndctl_dimm_ops) { .smart_get_flags = papr_smart_get_flags, .new_smart = papr_new_smart_health, .smart_get_health = papr_smart_get_health, + .smart_get_shutdown_state = papr_smart_get_shutdown_state, };