From patchwork Thu Jul 5 20:23:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 10510259 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 20D326024A for ; Thu, 5 Jul 2018 20:23:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 142EC2793B for ; Thu, 5 Jul 2018 20:23:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08DBE27B2F; Thu, 5 Jul 2018 20:23:03 +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=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, 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 A83452793B for ; Thu, 5 Jul 2018 20:23:02 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A1AF2210E3DFC; Thu, 5 Jul 2018 13:23:02 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=dave.jiang@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 CE52A210C278B for ; Thu, 5 Jul 2018 13:23:01 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Jul 2018 13:23:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,313,1526367600"; d="scan'208";a="70397198" Received: from djiang5-desk3.ch.intel.com ([143.182.136.93]) by orsmga001.jf.intel.com with ESMTP; 05 Jul 2018 13:23:01 -0700 Subject: [PATCH v2 09/11] nfit_test: adding context to dimm_dev for nfit_test From: Dave Jiang To: dan.j.williams@intel.com Date: Thu, 05 Jul 2018 13:23:01 -0700 Message-ID: <153082218106.61422.2990240314424211695.stgit@djiang5-desk3.ch.intel.com> In-Reply-To: <153082172527.61422.13689320279597181069.stgit@djiang5-desk3.ch.intel.com> References: <153082172527.61422.13689320279597181069.stgit@djiang5-desk3.ch.intel.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dhowells@redhat.com, alison.schofield@intel.com, keyrings@vger.kernel.org, keescook@chromium.org, linux-nvdimm@lists.01.org Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP In order to access the nfit_test context via sideband sysfs knobs, the dimm_dev needs to be more than struct device in order to point back to struct nfit_test. Wrapping the original struct device with a struct nfit_dimm_dev and saving the nfit_test as private driver data. Also changing the nfit_mem to be a member of struct nfit_dimm_dev instead of saving as private driver data of that device. This is in preparation for adding security DSM support and allowing the locking of DIMMs for testing via sideband. Signed-off-by: Dave Jiang --- tools/testing/nvdimm/test/nfit.c | 41 +++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/tools/testing/nvdimm/test/nfit.c b/tools/testing/nvdimm/test/nfit.c index 18157b0c0d0d..7b3ce2194889 100644 --- a/tools/testing/nvdimm/test/nfit.c +++ b/tools/testing/nvdimm/test/nfit.c @@ -150,6 +150,11 @@ struct nfit_test_fw { u64 end_time; }; +struct nfit_dimm_dev { + struct device dev; + struct nfit_mem *nfit_mem; +}; + struct nfit_test { struct acpi_nfit_desc acpi_desc; struct platform_device pdev; @@ -181,7 +186,7 @@ struct nfit_test { unsigned long deadline; spinlock_t lock; } ars_state; - struct device *dimm_dev[NUM_DCR]; + struct nfit_dimm_dev dimm_dev[NUM_DCR]; struct nd_intel_smart *smart; struct nd_intel_smart_threshold *smart_threshold; struct badrange badrange; @@ -981,7 +986,8 @@ static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc, &t->smart_threshold[i - t->dcr_idx], &t->smart[i - t->dcr_idx], - &t->pdev.dev, t->dimm_dev[i]); + &t->pdev.dev, + &t->dimm_dev[i].dev); break; case ND_INTEL_SMART_INJECT: rc = nfit_test_cmd_smart_inject(buf, @@ -989,7 +995,8 @@ static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc, &t->smart_threshold[i - t->dcr_idx], &t->smart[i - t->dcr_idx], - &t->pdev.dev, t->dimm_dev[i]); + &t->pdev.dev, + &t->dimm_dev[i].dev); break; default: return -ENOTTY; @@ -1187,8 +1194,7 @@ static void put_dimms(void *data) int i; for (i = 0; i < t->num_dcr; i++) - if (t->dimm_dev[i]) - device_unregister(t->dimm_dev[i]); + device_unregister(&t->dimm_dev[i].dev); } static struct class *nfit_test_dimm; @@ -1290,19 +1296,27 @@ static const struct attribute_group *nfit_test_dimm_attribute_groups[] = { NULL, }; +static void dimm_dev_release(struct device *dev) +{ +} + static int nfit_test_dimm_init(struct nfit_test *t) { - int i; + int i, rc; if (devm_add_action_or_reset(&t->pdev.dev, put_dimms, t)) return -ENOMEM; for (i = 0; i < t->num_dcr; i++) { - t->dimm_dev[i] = device_create_with_groups(nfit_test_dimm, - &t->pdev.dev, 0, NULL, - nfit_test_dimm_attribute_groups, - "test_dimm%d", i + t->dcr_idx); - if (!t->dimm_dev[i]) - return -ENOMEM; + t->dimm_dev[i].dev.parent = &t->pdev.dev; + dev_set_name(&t->dimm_dev[i].dev, "test_dimm%d", + i + t->dcr_idx); + t->dimm_dev[i].dev.class = nfit_test_dimm; + t->dimm_dev[i].dev.groups = nfit_test_dimm_attribute_groups; + t->dimm_dev[i].dev.release = dimm_dev_release; + rc = device_register(&t->dimm_dev[i].dev); + if (rc < 0) + return rc; + dev_set_drvdata(&t->dimm_dev[i].dev, t); } return 0; } @@ -2665,8 +2679,7 @@ static int nfit_test_probe(struct platform_device *pdev) for (i = 0; i < NUM_DCR; i++) if (nfit_handle == handle[i]) - dev_set_drvdata(nfit_test->dimm_dev[i], - nfit_mem); + nfit_test->dimm_dev[i].nfit_mem = nfit_mem; } mutex_unlock(&acpi_desc->init_mutex);