From patchwork Fri Jul 15 19:42:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9232507 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E5ABC60868 for ; Fri, 15 Jul 2016 19:45:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7C342621F for ; Fri, 15 Jul 2016 19:45:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC93426D08; Fri, 15 Jul 2016 19:45:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5D6762621F for ; Fri, 15 Jul 2016 19:45:12 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id DFB301A1F22; Fri, 15 Jul 2016 12:45:59 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by ml01.01.org (Postfix) with ESMTP id DB0F01A1F22 for ; Fri, 15 Jul 2016 12:45:58 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP; 15 Jul 2016 12:44:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.28,369,1464678000"; d="scan'208"; a="1017717898" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.14]) by orsmga002.jf.intel.com with ESMTP; 15 Jul 2016 12:44:55 -0700 Subject: [ndctl PATCH] ndctl: add ndctl_dimm_get_manufacturing_{date|location} apis From: Dan Williams To: linux-nvdimm@lists.01.org Date: Fri, 15 Jul 2016 12:42:45 -0700 Message-ID: <146861176516.17090.10204922835726487624.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kristin Jacque Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP This data is encoded in the unique_id. Since we provide standalone helpers to retrieve the other fields of the unique_id, do the same for these attributes. Reported-by: Kristin Jacque Signed-off-by: Dan Williams Reviewed-by: Vishal Verma --- ndctl/lib/libndctl.c | 24 ++++++++++++++++++++++++ ndctl/lib/libndctl.sym | 2 ++ ndctl/libndctl.h.in | 2 ++ test/libndctl.c | 20 +++++++++++++++----- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index 6860a4b6fa92..0722f79470c3 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -133,6 +133,8 @@ struct ndctl_dimm { unsigned short subsystem_vendor_id; unsigned short subsystem_device_id; unsigned short subsystem_revision_id; + unsigned short manufacturing_date; + unsigned char manufacturing_location; unsigned long dsm_mask; char *unique_id; char *dimm_path; @@ -1168,6 +1170,8 @@ static int add_dimm(void *parent, int id, const char *dimm_base) dimm->subsystem_vendor_id = -1; dimm->subsystem_device_id = -1; dimm->subsystem_revision_id = -1; + dimm->manufacturing_date = -1; + dimm->manufacturing_location = -1; for (i = 0; i < formats; i++) dimm->format[i] = -1; @@ -1180,9 +1184,17 @@ static int add_dimm(void *parent, int id, const char *dimm_base) */ sprintf(path, "%s/nfit/id", dimm_base); if (sysfs_read_attr(ctx, path, buf) == 0) { + unsigned int b[9]; + dimm->unique_id = strdup(buf); if (!dimm->unique_id) goto err_read; + if (sscanf(dimm->unique_id, "%02x%02x-%02x-%02x%02x-%02x%02x%02x%02x", + &b[0], &b[1], &b[2], &b[3], &b[4], + &b[5], &b[6], &b[7], &b[8]) == 9) { + dimm->manufacturing_date = b[3] << 8 | b[4]; + dimm->manufacturing_location = b[2]; + } } sprintf(path, "%s/nfit/handle", dimm_base); @@ -1315,6 +1327,18 @@ NDCTL_EXPORT unsigned short ndctl_dimm_get_subsystem_revision( return dimm->subsystem_revision_id; } +NDCTL_EXPORT unsigned short ndctl_dimm_get_manufacturing_date( + struct ndctl_dimm *dimm) +{ + return dimm->manufacturing_date; +} + +NDCTL_EXPORT unsigned char ndctl_dimm_get_manufacturing_location( + struct ndctl_dimm *dimm) +{ + return dimm->manufacturing_location; +} + NDCTL_EXPORT unsigned short ndctl_dimm_get_format(struct ndctl_dimm *dimm) { return dimm->format[0]; diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym index a22732467f8a..6af267a04191 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -41,6 +41,8 @@ global: ndctl_dimm_get_vendor; ndctl_dimm_get_device; ndctl_dimm_get_revision; + ndctl_dimm_get_manufacturing_date; + ndctl_dimm_get_manufacturing_location; ndctl_dimm_get_subsystem_vendor; ndctl_dimm_get_subsystem_device; ndctl_dimm_get_subsystem_revision; diff --git a/ndctl/libndctl.h.in b/ndctl/libndctl.h.in index e6766cef56bb..9e0e82acfd2f 100644 --- a/ndctl/libndctl.h.in +++ b/ndctl/libndctl.h.in @@ -124,6 +124,8 @@ unsigned short ndctl_dimm_get_device(struct ndctl_dimm *dimm); unsigned short ndctl_dimm_get_revision(struct ndctl_dimm *dimm); unsigned short ndctl_dimm_get_subsystem_vendor(struct ndctl_dimm *dimm); unsigned short ndctl_dimm_get_subsystem_device(struct ndctl_dimm *dimm); +unsigned short ndctl_dimm_get_manufacturing_date(struct ndctl_dimm *dimm); +unsigned char ndctl_dimm_get_manufacturing_location(struct ndctl_dimm *dimm); unsigned short ndctl_dimm_get_subsystem_revision(struct ndctl_dimm *dimm); unsigned short ndctl_dimm_get_format(struct ndctl_dimm *dimm); int ndctl_dimm_get_formats(struct ndctl_dimm *dimm); diff --git a/test/libndctl.c b/test/libndctl.c index b03fc27a5f0b..011d905f7fb4 100644 --- a/test/libndctl.c +++ b/test/libndctl.c @@ -118,6 +118,8 @@ struct dimm { unsigned int handle; unsigned int phys_id; unsigned int subsystem_vendor; + unsigned short manufacturing_date; + unsigned char manufacturing_location; union { unsigned long flags; struct { @@ -136,15 +138,15 @@ struct dimm { (((n & 0xfff) << 16) | ((s & 0xf) << 12) | ((i & 0xf) << 8) \ | ((c & 0xf) << 4) | (d & 0xf)) static struct dimm dimms0[] = { - { DIMM_HANDLE(0, 0, 0, 0, 0), 0, 0, { 0 }, 2, { 0x201, 0x301, }, }, - { DIMM_HANDLE(0, 0, 0, 0, 1), 1, 0, { 0 }, 2, { 0x201, 0x301, }, }, - { DIMM_HANDLE(0, 0, 1, 0, 0), 2, 0, { 0 }, 2, { 0x201, 0x301, }, }, - { DIMM_HANDLE(0, 0, 1, 0, 1), 3, 0, { 0 }, 2, { 0x201, 0x301, }, }, + { DIMM_HANDLE(0, 0, 0, 0, 0), 0, 0, 2016, 10, { 0 }, 2, { 0x201, 0x301, }, }, + { DIMM_HANDLE(0, 0, 0, 0, 1), 1, 0, 2016, 10, { 0 }, 2, { 0x201, 0x301, }, }, + { DIMM_HANDLE(0, 0, 1, 0, 0), 2, 0, 2016, 10, { 0 }, 2, { 0x201, 0x301, }, }, + { DIMM_HANDLE(0, 0, 1, 0, 1), 3, 0, 2016, 10, { 0 }, 2, { 0x201, 0x301, }, }, }; static struct dimm dimms1[] = { { - DIMM_HANDLE(0, 0, 0, 0, 0), 0, 0, { + DIMM_HANDLE(0, 0, 0, 0, 0), 0, 0, 2016, 10, { .f_arm = 1, .f_save = 1, .f_flush = 1, @@ -2386,6 +2388,14 @@ static int check_dimms(struct ndctl_bus *bus, struct dimm *dimms, int n, return -ENXIO; } + if (ndctl_dimm_get_manufacturing_date(dimm) + != dimms[i].manufacturing_date) { + fprintf(stderr, "dimm%d expected manufacturing date: %d got: %d\n", + i, dimms[i].manufacturing_date, + ndctl_dimm_get_manufacturing_date(dimm)); + return -ENXIO; + } + rc = check_commands(bus, dimm, bus_commands, dimm_commands, test); if (rc) return rc;