From: Vaibhav Jain <vaibhav@linux.ibm.com>
To: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>,
linux-nvdimm@lists.01.org
Subject: Re: [ndctl PATCH v2 1/6] libndctl: Refactor out add_dimm() to handle NFIT specific init
Date: Mon, 04 May 2020 13:35:31 +0530 [thread overview]
Message-ID: <87imhcdt10.fsf@linux.ibm.com> (raw)
In-Reply-To: <87ftcm20gm.fsf@linux.ibm.com>
Hi Aneesh,
Thanks for looking into this patch.
"Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com> writes:
> Vaibhav Jain <vaibhav@linux.ibm.com> writes:
>
>> 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 <vaibhav@linux.ibm.com>
>> ---
>> Changelog:
>>
>> v1..v2:
>> * None
>> ---
>> 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 ee737cbbfe3e..d76dbf7e17de 100644
>> --- a/ndctl/lib/libndctl.c
>> +++ b/ndctl/lib/libndctl.c
>> @@ -1441,82 +1441,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
>
> ....
>> + 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);
>
> Witht that abstraction this should be part of add_nfit_dimm?
This part is needed to calculate the size of 'struct ndctl_dimm' to be
allocated which is based on number of nfit formats reported in
sysfs.
>
>> + 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;
>> +
> _______________________________________________
> Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
> To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
~ Vaibhav
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
next prev parent reply other threads:[~2020-05-04 8:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-20 7:55 [ndctl PATCH v2 0/6] Add support for reporting papr-scm nvdimm health Vaibhav Jain
2020-04-20 7:55 ` [ndctl PATCH v2 1/6] libndctl: Refactor out add_dimm() to handle NFIT specific init Vaibhav Jain
2020-04-24 3:18 ` Santosh Sivaraj
2020-04-29 7:52 ` Aneesh Kumar K.V
2020-05-04 8:05 ` Vaibhav Jain [this message]
2020-04-20 7:55 ` [ndctl PATCH v2 2/6] libncdtl: Add initial support for NVDIMM_FAMILY_PAPR_SCM dimm family Vaibhav Jain
2020-04-29 7:55 ` Aneesh Kumar K.V
2020-05-04 8:31 ` Vaibhav Jain
2020-04-20 7:55 ` [ndctl PATCH v2 3/6] libndctl: Introduce new dimm-ops dimm_init() & dimm_uninit() Vaibhav Jain
2020-04-20 7:55 ` [ndctl PATCH v2 4/6] libndctl,papr_scm: Add definitions for PAPR nvdimm specific methods Vaibhav Jain
2020-04-20 7:55 ` [ndctl PATCH v2 5/6] libndctl,papr_scm: Add scaffolding to issue and handle PDSM requests Vaibhav Jain
2020-04-20 7:55 ` [ndctl PATCH v2 6/6] libndctl,papr_scm: Implement support for PAPR_SCM_PDSM_HEALTH Vaibhav Jain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87imhcdt10.fsf@linux.ibm.com \
--to=vaibhav@linux.ibm.com \
--cc=aneesh.kumar@linux.ibm.com \
--cc=linux-nvdimm@lists.01.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.