History

Merge branch 'for-5.8/papr_scm' into libnvdimm-for-next

Include the papr_scm health retrieval feature for v5.8-rc2. The functionality was initially posted well in advance of the merge window, but review comments and a late build-bot warning kept them out of the v5.8-rc1 libnvdimm pull request. Vaibhav notes: These patches are tied to specific features that were committed to customers in upcoming distros releases (RHEL and SLES) whose time-lines are tied to 5.8 kernel release. Being able to track the health of an nvdimm is critical for our customers that are running workloads leveraging papr-scm nvdimms. Missing the 5.8 kernel would mean missing the distro timelines and shifting forward the availability of this feature in distro kernels by at least 6 months.

Dan Williams committed 6 years ago

Commit 9df24ea2 parents 543094e d35f18b6 files · +616 −11Browse files

Unified · Split

6 files
  1. Documentation/ABI/testing/sysfs-bus-papr-pmem +27 −0
  2. Documentation/powerpc/papr_hcalls.rst +42 −4
  3. arch/powerpc/include/uapi/asm/papr_pdsm.h +132 −0
  4. arch/powerpc/platforms/pseries/papr_scm.c +413 −7
  5. include/uapi/linux/ndctl.h +1 −0
  6. lib/seq_buf.c +1 −0
Documentation/ABI/testing/sysfs-bus-papr-pmem+27−0
@@ -0,0 +1,27 @@
1What: /sys/bus/nd/devices/nmemX/papr/flags
2Date: Apr, 2020
3KernelVersion: v5.8
4Contact: linuxppc-dev <linuxppc-dev@lists.ozlabs.org>, linux-nvdimm@lists.01.org,
5Description:
6 (RO) Report flags indicating various states of a
7 papr-pmem NVDIMM device. Each flag maps to a one or
8 more bits set in the dimm-health-bitmap retrieved in
9 response to H_SCM_HEALTH hcall. The details of the bit
10 flags returned in response to this hcall is available
11 at 'Documentation/powerpc/papr_hcalls.rst' . Below are
12 the flags reported in this sysfs file:
13
14 * "not_armed" : Indicates that NVDIMM contents will not
15 survive a power cycle.
16 * "flush_fail" : Indicates that NVDIMM contents
17 couldn't be flushed during last
18 shut-down event.
19 * "restore_fail": Indicates that NVDIMM contents
20 couldn't be restored during NVDIMM
21 initialization.
22 * "encrypted" : NVDIMM contents are encrypted.
23 * "smart_notify": There is health event for the NVDIMM.
24 * "scrubbed" : Indicating that contents of the
25 NVDIMM have been scrubbed.
26 * "locked" : Indicating that NVDIMM contents cant
27 be modified until next power cycle.
Documentation/powerpc/papr_hcalls.rst+42−4
@@ -220,13 +220,51 @@ from the LPAR memory. · 219 unmodified lines
220**H_SCM_HEALTH**220**H_SCM_HEALTH**
221 221
222| Input: drcIndex222| Input: drcIndex
223| Out: *health-bitmap, health-bit-valid-bitmap*223| Out: *health-bitmap (r4), health-bit-valid-bitmap (r5)*
224| Return Value: *H_Success, H_Parameter, H_Hardware*224| Return Value: *H_Success, H_Parameter, H_Hardware*
225 225
226Given a DRC Index return the info on predictive failure and overall health of226Given a DRC Index return the info on predictive failure and overall health of
227the NVDIMM. The asserted bits in the health-bitmap indicate a single predictive227the PMEM device. The asserted bits in the health-bitmap indicate one or more states
228failure and health-bit-valid-bitmap indicate which bits in health-bitmap are228(described in table below) of the PMEM device and health-bit-valid-bitmap indicate
229valid.229which bits in health-bitmap are valid. The bits are reported in
230reverse bit ordering for example a value of 0xC400000000000000
231indicates bits 0, 1, and 5 are valid.
232
233Health Bitmap Flags:
234
235+------+-----------------------------------------------------------------------+
236| Bit | Definition |
237+======+=======================================================================+
238| 00 | PMEM device is unable to persist memory contents. |
239| | If the system is powered down, nothing will be saved. |
240+------+-----------------------------------------------------------------------+
241| 01 | PMEM device failed to persist memory contents. Either contents were |
242| | not saved successfully on power down or were not restored properly on |
243| | power up. |
244+------+-----------------------------------------------------------------------+
245| 02 | PMEM device contents are persisted from previous IPL. The data from |
246| | the last boot were successfully restored. |
247+------+-----------------------------------------------------------------------+
248| 03 | PMEM device contents are not persisted from previous IPL. There was no|
249| | data to restore from the last boot. |
250+------+-----------------------------------------------------------------------+
251| 04 | PMEM device memory life remaining is critically low |
252+------+-----------------------------------------------------------------------+
253| 05 | PMEM device will be garded off next IPL due to failure |
254+------+-----------------------------------------------------------------------+
255| 06 | PMEM device contents cannot persist due to current platform health |
256| | status. A hardware failure may prevent data from being saved or |
257| | restored. |
258+------+-----------------------------------------------------------------------+
259| 07 | PMEM device is unable to persist memory contents in certain conditions|
260+------+-----------------------------------------------------------------------+
261| 08 | PMEM device is encrypted |
262+------+-----------------------------------------------------------------------+
263| 09 | PMEM device has successfully completed a requested erase or secure |
264| | erase procedure. |
265+------+-----------------------------------------------------------------------+
266|10:63 | Reserved / Unused |
267+------+-----------------------------------------------------------------------+
230 268
231**H_SCM_PERFORMANCE_STATS**269**H_SCM_PERFORMANCE_STATS**
232 270
arch/powerpc/include/uapi/asm/papr_pdsm.h+132−0
@@ -0,0 +1,132 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * PAPR nvDimm Specific Methods (PDSM) and structs for libndctl
4 *
5 * (C) Copyright IBM 2020
6 *
7 * Author: Vaibhav Jain <vaibhav at linux.ibm.com>
8 */
9
10#ifndef _UAPI_ASM_POWERPC_PAPR_PDSM_H_
11#define _UAPI_ASM_POWERPC_PAPR_PDSM_H_
12
13#include <linux/types.h>
14#include <linux/ndctl.h>
15
16/*
17 * PDSM Envelope:
18 *
19 * The ioctl ND_CMD_CALL exchange data between user-space and kernel via
20 * envelope which consists of 2 headers sections and payload sections as
21 * illustrated below:
22 * +-----------------+---------------+---------------------------+
23 * | 64-Bytes | 8-Bytes | Max 184-Bytes |
24 * +-----------------+---------------+---------------------------+
25 * | ND-HEADER | PDSM-HEADER | PDSM-PAYLOAD |
26 * +-----------------+---------------+---------------------------+
27 * | nd_family | | |
28 * | nd_size_out | cmd_status | |
29 * | nd_size_in | reserved | nd_pdsm_payload |
30 * | nd_command | payload --> | |
31 * | nd_fw_size | | |
32 * | nd_payload ---> | | |
33 * +---------------+-----------------+---------------------------+
34 *
35 * ND Header:
36 * This is the generic libnvdimm header described as 'struct nd_cmd_pkg'
37 * which is interpreted by libnvdimm before passed on to papr_scm. Important
38 * member fields used are:
39 * 'nd_family' : (In) NVDIMM_FAMILY_PAPR_SCM
40 * 'nd_size_in' : (In) PDSM-HEADER + PDSM-IN-PAYLOAD (usually 0)
41 * 'nd_size_out' : (In) PDSM-HEADER + PDSM-RETURN-PAYLOAD
42 * 'nd_command' : (In) One of PAPR_PDSM_XXX
43 * 'nd_fw_size' : (Out) PDSM-HEADER + size of actual payload returned
44 *
45 * PDSM Header:
46 * This is papr-scm specific header that precedes the payload. This is defined
47 * as nd_cmd_pdsm_pkg. Following fields aare available in this header:
48 *
49 * 'cmd_status' : (Out) Errors if any encountered while servicing PDSM.
50 * 'reserved' : Not used, reserved for future and should be set to 0.
51 * 'payload' : A union of all the possible payload structs
52 *
53 * PDSM Payload:
54 *
55 * The layout of the PDSM Payload is defined by various structs shared between
56 * papr_scm and libndctl so that contents of payload can be interpreted. As such
57 * its defined as a union of all possible payload structs as
58 * 'union nd_pdsm_payload'. Based on the value of 'nd_cmd_pkg.nd_command'
59 * appropriate member of the union is accessed.
60 */
61
62/* Max payload size that we can handle */
63#define ND_PDSM_PAYLOAD_MAX_SIZE 184
64
65/* Max payload size that we can handle */
66#define ND_PDSM_HDR_SIZE \
67 (sizeof(struct nd_pkg_pdsm) - ND_PDSM_PAYLOAD_MAX_SIZE)
68
69/* Various nvdimm health indicators */
70#define PAPR_PDSM_DIMM_HEALTHY 0
71#define PAPR_PDSM_DIMM_UNHEALTHY 1
72#define PAPR_PDSM_DIMM_CRITICAL 2
73#define PAPR_PDSM_DIMM_FATAL 3
74
75/*
76 * Struct exchanged between kernel & ndctl in for PAPR_PDSM_HEALTH
77 * Various flags indicate the health status of the dimm.
78 *
79 * extension_flags : Any extension fields present in the struct.
80 * dimm_unarmed : Dimm not armed. So contents wont persist.
81 * dimm_bad_shutdown : Previous shutdown did not persist contents.
82 * dimm_bad_restore : Contents from previous shutdown werent restored.
83 * dimm_scrubbed : Contents of the dimm have been scrubbed.
84 * dimm_locked : Contents of the dimm cant be modified until CEC reboot
85 * dimm_encrypted : Contents of dimm are encrypted.
86 * dimm_health : Dimm health indicator. One of PAPR_PDSM_DIMM_XXXX
87 */
88struct nd_papr_pdsm_health {
89 union {
90 struct {
91 __u32 extension_flags;
92 __u8 dimm_unarmed;
93 __u8 dimm_bad_shutdown;
94 __u8 dimm_bad_restore;
95 __u8 dimm_scrubbed;
96 __u8 dimm_locked;
97 __u8 dimm_encrypted;
98 __u16 dimm_health;
99 };
100 __u8 buf[ND_PDSM_PAYLOAD_MAX_SIZE];
101 };
102};
103
104/*
105 * Methods to be embedded in ND_CMD_CALL request. These are sent to the kernel
106 * via 'nd_cmd_pkg.nd_command' member of the ioctl struct
107 */
108enum papr_pdsm {
109 PAPR_PDSM_MIN = 0x0,
110 PAPR_PDSM_HEALTH,
111 PAPR_PDSM_MAX,
112};
113
114/* Maximal union that can hold all possible payload types */
115union nd_pdsm_payload {
116 struct nd_papr_pdsm_health health;
117 __u8 buf[ND_PDSM_PAYLOAD_MAX_SIZE];
118} __packed;
119
120/*
121 * PDSM-header + payload expected with ND_CMD_CALL ioctl from libnvdimm
122 * Valid member of union 'payload' is identified via 'nd_cmd_pkg.nd_command'
123 * that should always precede this struct when sent to papr_scm via CMD_CALL
124 * interface.
125 */
126struct nd_pkg_pdsm {
127 __s32 cmd_status; /* Out: Sub-cmd status returned back */
128 __u16 reserved[2]; /* Ignored and to be set as '0' */
129 union nd_pdsm_payload payload;
130} __packed;
131
132#endif /* _UAPI_ASM_POWERPC_PAPR_PDSM_H_ */
arch/powerpc/platforms/pseries/papr_scm.c+413−7
@@ -12,16 +12,57 @@ · 11 unmodified lines
12#include <linux/libnvdimm.h>12#include <linux/libnvdimm.h>
13#include <linux/platform_device.h>13#include <linux/platform_device.h>
14#include <linux/delay.h>14#include <linux/delay.h>
15#include <linux/seq_buf.h>
15 16
16#include <asm/plpar_wrappers.h>17#include <asm/plpar_wrappers.h>
18#include <asm/papr_pdsm.h>
17 19
18#define BIND_ANY_ADDR (~0ul)20#define BIND_ANY_ADDR (~0ul)
19 21
20#define PAPR_SCM_DIMM_CMD_MASK \22#define PAPR_SCM_DIMM_CMD_MASK \
21 ((1ul << ND_CMD_GET_CONFIG_SIZE) | \23 ((1ul << ND_CMD_GET_CONFIG_SIZE) | \
22 (1ul << ND_CMD_GET_CONFIG_DATA) | \24 (1ul << ND_CMD_GET_CONFIG_DATA) | \
23 (1ul << ND_CMD_SET_CONFIG_DATA))25 (1ul << ND_CMD_SET_CONFIG_DATA) | \
24 26 (1ul << ND_CMD_CALL))
27
28/* DIMM health bitmap bitmap indicators */
29/* SCM device is unable to persist memory contents */
30#define PAPR_PMEM_UNARMED (1ULL << (63 - 0))
31/* SCM device failed to persist memory contents */
32#define PAPR_PMEM_SHUTDOWN_DIRTY (1ULL << (63 - 1))
33/* SCM device contents are persisted from previous IPL */
34#define PAPR_PMEM_SHUTDOWN_CLEAN (1ULL << (63 - 2))
35/* SCM device contents are not persisted from previous IPL */
36#define PAPR_PMEM_EMPTY (1ULL << (63 - 3))
37/* SCM device memory life remaining is critically low */
38#define PAPR_PMEM_HEALTH_CRITICAL (1ULL << (63 - 4))
39/* SCM device will be garded off next IPL due to failure */
40#define PAPR_PMEM_HEALTH_FATAL (1ULL << (63 - 5))
41/* SCM contents cannot persist due to current platform health status */
42#define PAPR_PMEM_HEALTH_UNHEALTHY (1ULL << (63 - 6))
43/* SCM device is unable to persist memory contents in certain conditions */
44#define PAPR_PMEM_HEALTH_NON_CRITICAL (1ULL << (63 - 7))
45/* SCM device is encrypted */
46#define PAPR_PMEM_ENCRYPTED (1ULL << (63 - 8))
47/* SCM device has been scrubbed and locked */
48#define PAPR_PMEM_SCRUBBED_AND_LOCKED (1ULL << (63 - 9))
49
50/* Bits status indicators for health bitmap indicating unarmed dimm */
51#define PAPR_PMEM_UNARMED_MASK (PAPR_PMEM_UNARMED | \
52 PAPR_PMEM_HEALTH_UNHEALTHY)
53
54/* Bits status indicators for health bitmap indicating unflushed dimm */
55#define PAPR_PMEM_BAD_SHUTDOWN_MASK (PAPR_PMEM_SHUTDOWN_DIRTY)
56
57/* Bits status indicators for health bitmap indicating unrestored dimm */
58#define PAPR_PMEM_BAD_RESTORE_MASK (PAPR_PMEM_EMPTY)
59
60/* Bit status indicators for smart event notification */
61#define PAPR_PMEM_SMART_EVENT_MASK (PAPR_PMEM_HEALTH_CRITICAL | \
62 PAPR_PMEM_HEALTH_FATAL | \
63 PAPR_PMEM_HEALTH_UNHEALTHY)
64
65/* private struct associated with each region */
25struct papr_scm_priv {66struct papr_scm_priv {
26 struct platform_device *pdev;67 struct platform_device *pdev;
27 struct device_node *dn;68 struct device_node *dn;
@@ -39,6 +80,15 @@ struct papr_scm_priv { · 11 unmodified lines
39 struct resource res;80 struct resource res;
40 struct nd_region *region;81 struct nd_region *region;
41 struct nd_interleave_set nd_set;82 struct nd_interleave_set nd_set;
83
84 /* Protect dimm health data from concurrent read/writes */
85 struct mutex health_mutex;
86
87 /* Last time the health information of the dimm was updated */
88 unsigned long lasthealth_jiffies;
89
90 /* Health information for the dimm */
91 u64 health_bitmap;
42};92};
43 93
44static int drc_pmem_bind(struct papr_scm_priv *p)94static int drc_pmem_bind(struct papr_scm_priv *p)
@@ -144,6 +194,61 @@ err_out: · 99 unmodified lines
144 return drc_pmem_bind(p);194 return drc_pmem_bind(p);
145}195}
146 196
197/*
198 * Issue hcall to retrieve dimm health info and populate papr_scm_priv with the
199 * health information.
200 */
201static int __drc_pmem_query_health(struct papr_scm_priv *p)
202{
203 unsigned long ret[PLPAR_HCALL_BUFSIZE];
204 long rc;
205
206 /* issue the hcall */
207 rc = plpar_hcall(H_SCM_HEALTH, ret, p->drc_index);
208 if (rc != H_SUCCESS) {
209 dev_err(&p->pdev->dev,
210 "Failed to query health information, Err:%ld\n", rc);
211 return -ENXIO;
212 }
213
214 p->lasthealth_jiffies = jiffies;
215 p->health_bitmap = ret[0] & ret[1];
216
217 dev_dbg(&p->pdev->dev,
218 "Queried dimm health info. Bitmap:0x%016lx Mask:0x%016lx\n",
219 ret[0], ret[1]);
220
221 return 0;
222}
223
224/* Min interval in seconds for assuming stable dimm health */
225#define MIN_HEALTH_QUERY_INTERVAL 60
226
227/* Query cached health info and if needed call drc_pmem_query_health */
228static int drc_pmem_query_health(struct papr_scm_priv *p)
229{
230 unsigned long cache_timeout;
231 int rc;
232
233 /* Protect concurrent modifications to papr_scm_priv */
234 rc = mutex_lock_interruptible(&p->health_mutex);
235 if (rc)
236 return rc;
237
238 /* Jiffies offset for which the health data is assumed to be same */
239 cache_timeout = p->lasthealth_jiffies +
240 msecs_to_jiffies(MIN_HEALTH_QUERY_INTERVAL * 1000);
241
242 /* Fetch new health info is its older than MIN_HEALTH_QUERY_INTERVAL */
243 if (time_after(jiffies, cache_timeout))
244 rc = __drc_pmem_query_health(p);
245 else
246 /* Assume cached health data is valid */
247 rc = 0;
248
249 mutex_unlock(&p->health_mutex);
250 return rc;
251}
147 252
148static int papr_scm_meta_get(struct papr_scm_priv *p,253static int papr_scm_meta_get(struct papr_scm_priv *p,
149 struct nd_cmd_get_config_data_hdr *hdr)254 struct nd_cmd_get_config_data_hdr *hdr)
@@ -246,16 +351,250 @@ static int papr_scm_meta_set(struct papr_scm_priv *p, · 96 unmodified lines
246 return 0;351 return 0;
247}352}
248 353
354/*
355 * Do a sanity checks on the inputs args to dimm-control function and return
356 * '0' if valid. Validation of PDSM payloads happens later in
357 * papr_scm_service_pdsm.
358 */
359static int is_cmd_valid(struct nvdimm *nvdimm, unsigned int cmd, void *buf,
360 unsigned int buf_len)
361{
362 unsigned long cmd_mask = PAPR_SCM_DIMM_CMD_MASK;
363 struct nd_cmd_pkg *nd_cmd;
364 struct papr_scm_priv *p;
365 enum papr_pdsm pdsm;
366
367 /* Only dimm-specific calls are supported atm */
368 if (!nvdimm)
369 return -EINVAL;
370
371 /* get the provider data from struct nvdimm */
372 p = nvdimm_provider_data(nvdimm);
373
374 if (!test_bit(cmd, &cmd_mask)) {
375 dev_dbg(&p->pdev->dev, "Unsupported cmd=%u\n", cmd);
376 return -EINVAL;
377 }
378
379 /* For CMD_CALL verify pdsm request */
380 if (cmd == ND_CMD_CALL) {
381 /* Verify the envelope and envelop size */
382 if (!buf ||
383 buf_len < (sizeof(struct nd_cmd_pkg) + ND_PDSM_HDR_SIZE)) {
384 dev_dbg(&p->pdev->dev, "Invalid pkg size=%u\n",
385 buf_len);
386 return -EINVAL;
387 }
388
389 /* Verify that the nd_cmd_pkg.nd_family is correct */
390 nd_cmd = (struct nd_cmd_pkg *)buf;
391
392 if (nd_cmd->nd_family != NVDIMM_FAMILY_PAPR) {
393 dev_dbg(&p->pdev->dev, "Invalid pkg family=0x%llx\n",
394 nd_cmd->nd_family);
395 return -EINVAL;
396 }
397
398 pdsm = (enum papr_pdsm)nd_cmd->nd_command;
399
400 /* Verify if the pdsm command is valid */
401 if (pdsm <= PAPR_PDSM_MIN || pdsm >= PAPR_PDSM_MAX) {
402 dev_dbg(&p->pdev->dev, "PDSM[0x%x]: Invalid PDSM\n",
403 pdsm);
404 return -EINVAL;
405 }
406
407 /* Have enough space to hold returned 'nd_pkg_pdsm' header */
408 if (nd_cmd->nd_size_out < ND_PDSM_HDR_SIZE) {
409 dev_dbg(&p->pdev->dev, "PDSM[0x%x]: Invalid payload\n",
410 pdsm);
411 return -EINVAL;
412 }
413 }
414
415 /* Let the command be further processed */
416 return 0;
417}
418
419/* Fetch the DIMM health info and populate it in provided package. */
420static int papr_pdsm_health(struct papr_scm_priv *p,
421 union nd_pdsm_payload *payload)
422{
423 int rc;
424
425 /* Ensure dimm health mutex is taken preventing concurrent access */
426 rc = mutex_lock_interruptible(&p->health_mutex);
427 if (rc)
428 goto out;
429
430 /* Always fetch upto date dimm health data ignoring cached values */
431 rc = __drc_pmem_query_health(p);
432 if (rc) {
433 mutex_unlock(&p->health_mutex);
434 goto out;
435 }
436
437 /* update health struct with various flags derived from health bitmap */
438 payload->health = (struct nd_papr_pdsm_health) {
439 .extension_flags = 0,
440 .dimm_unarmed = !!(p->health_bitmap & PAPR_PMEM_UNARMED_MASK),
441 .dimm_bad_shutdown = !!(p->health_bitmap & PAPR_PMEM_BAD_SHUTDOWN_MASK),
442 .dimm_bad_restore = !!(p->health_bitmap & PAPR_PMEM_BAD_RESTORE_MASK),
443 .dimm_scrubbed = !!(p->health_bitmap & PAPR_PMEM_SCRUBBED_AND_LOCKED),
444 .dimm_locked = !!(p->health_bitmap & PAPR_PMEM_SCRUBBED_AND_LOCKED),
445 .dimm_encrypted = !!(p->health_bitmap & PAPR_PMEM_ENCRYPTED),
446 .dimm_health = PAPR_PDSM_DIMM_HEALTHY,
447 };
448
449 /* Update field dimm_health based on health_bitmap flags */
450 if (p->health_bitmap & PAPR_PMEM_HEALTH_FATAL)
451 payload->health.dimm_health = PAPR_PDSM_DIMM_FATAL;
452 else if (p->health_bitmap & PAPR_PMEM_HEALTH_CRITICAL)
453 payload->health.dimm_health = PAPR_PDSM_DIMM_CRITICAL;
454 else if (p->health_bitmap & PAPR_PMEM_HEALTH_UNHEALTHY)
455 payload->health.dimm_health = PAPR_PDSM_DIMM_UNHEALTHY;
456
457 /* struct populated hence can release the mutex now */
458 mutex_unlock(&p->health_mutex);
459 rc = sizeof(struct nd_papr_pdsm_health);
460
461out:
462 return rc;
463}
464
465/*
466 * 'struct pdsm_cmd_desc'
467 * Identifies supported PDSMs' expected length of in/out payloads
468 * and pdsm service function.
469 *
470 * size_in : Size of input payload if any in the PDSM request.
471 * size_out : Size of output payload if any in the PDSM request.
472 * service : Service function for the PDSM request. Return semantics:
473 * rc < 0 : Error servicing PDSM and rc indicates the error.
474 * rc >=0 : Serviced successfully and 'rc' indicate number of
475 * bytes written to payload.
476 */
477struct pdsm_cmd_desc {
478 u32 size_in;
479 u32 size_out;
480 int (*service)(struct papr_scm_priv *dimm,
481 union nd_pdsm_payload *payload);
482};
483
484/* Holds all supported PDSMs' command descriptors */
485static const struct pdsm_cmd_desc __pdsm_cmd_descriptors[] = {
486 [PAPR_PDSM_MIN] = {
487 .size_in = 0,
488 .size_out = 0,
489 .service = NULL,
490 },
491 /* New PDSM command descriptors to be added below */
492
493 [PAPR_PDSM_HEALTH] = {
494 .size_in = 0,
495 .size_out = sizeof(struct nd_papr_pdsm_health),
496 .service = papr_pdsm_health,
497 },
498 /* Empty */
499 [PAPR_PDSM_MAX] = {
500 .size_in = 0,
501 .size_out = 0,
502 .service = NULL,
503 },
504};
505
506/* Given a valid pdsm cmd return its command descriptor else return NULL */
507static inline const struct pdsm_cmd_desc *pdsm_cmd_desc(enum papr_pdsm cmd)
508{
509 if (cmd >= 0 || cmd < ARRAY_SIZE(__pdsm_cmd_descriptors))
510 return &__pdsm_cmd_descriptors[cmd];
511
512 return NULL;
513}
514
515/*
516 * For a given pdsm request call an appropriate service function.
517 * Returns errors if any while handling the pdsm command package.
518 */
519static int papr_scm_service_pdsm(struct papr_scm_priv *p,
520 struct nd_cmd_pkg *pkg)
521{
522 /* Get the PDSM header and PDSM command */
523 struct nd_pkg_pdsm *pdsm_pkg = (struct nd_pkg_pdsm *)pkg->nd_payload;
524 enum papr_pdsm pdsm = (enum papr_pdsm)pkg->nd_command;
525 const struct pdsm_cmd_desc *pdsc;
526 int rc;
527
528 /* Fetch corresponding pdsm descriptor for validation and servicing */
529 pdsc = pdsm_cmd_desc(pdsm);
530
531 /* Validate pdsm descriptor */
532 /* Ensure that reserved fields are 0 */
533 if (pdsm_pkg->reserved[0] || pdsm_pkg->reserved[1]) {
534 dev_dbg(&p->pdev->dev, "PDSM[0x%x]: Invalid reserved field\n",
535 pdsm);
536 return -EINVAL;
537 }
538
539 /* If pdsm expects some input, then ensure that the size_in matches */
540 if (pdsc->size_in &&
541 pkg->nd_size_in != (pdsc->size_in + ND_PDSM_HDR_SIZE)) {
542 dev_dbg(&p->pdev->dev, "PDSM[0x%x]: Mismatched size_in=%d\n",
543 pdsm, pkg->nd_size_in);
544 return -EINVAL;
545 }
546
547 /* If pdsm wants to return data, then ensure that size_out matches */
548 if (pdsc->size_out &&
549 pkg->nd_size_out != (pdsc->size_out + ND_PDSM_HDR_SIZE)) {
550 dev_dbg(&p->pdev->dev, "PDSM[0x%x]: Mismatched size_out=%d\n",
551 pdsm, pkg->nd_size_out);
552 return -EINVAL;
553 }
554
555 /* Service the pdsm */
556 if (pdsc->service) {
557 dev_dbg(&p->pdev->dev, "PDSM[0x%x]: Servicing..\n", pdsm);
558
559 rc = pdsc->service(p, &pdsm_pkg->payload);
560
561 if (rc < 0) {
562 /* error encountered while servicing pdsm */
563 pdsm_pkg->cmd_status = rc;
564 pkg->nd_fw_size = ND_PDSM_HDR_SIZE;
565 } else {
566 /* pdsm serviced and 'rc' bytes written to payload */
567 pdsm_pkg->cmd_status = 0;
568 pkg->nd_fw_size = ND_PDSM_HDR_SIZE + rc;
569 }
570 } else {
571 dev_dbg(&p->pdev->dev, "PDSM[0x%x]: Unsupported PDSM request\n",
572 pdsm);
573 pdsm_pkg->cmd_status = -ENOENT;
574 pkg->nd_fw_size = ND_PDSM_HDR_SIZE;
575 }
576
577 return pdsm_pkg->cmd_status;
578}
579
249static int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc,580static int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc,
250 struct nvdimm *nvdimm, unsigned int cmd, void *buf,581 struct nvdimm *nvdimm, unsigned int cmd, void *buf,
251 unsigned int buf_len, int *cmd_rc)582 unsigned int buf_len, int *cmd_rc)
252{583{
253 struct nd_cmd_get_config_size *get_size_hdr;584 struct nd_cmd_get_config_size *get_size_hdr;
585 struct nd_cmd_pkg *call_pkg = NULL;
254 struct papr_scm_priv *p;586 struct papr_scm_priv *p;
587 int rc;
255 588
256 /* Only dimm-specific calls are supported atm */589 rc = is_cmd_valid(nvdimm, cmd, buf, buf_len);
257 if (!nvdimm)590 if (rc) {
258 return -EINVAL;591 pr_debug("Invalid cmd=0x%x. Err=%d\n", cmd, rc);
592 return rc;
593 }
594
595 /* Use a local variable in case cmd_rc pointer is NULL */
596 if (!cmd_rc)
597 cmd_rc = &rc;
259 598
260 p = nvdimm_provider_data(nvdimm);599 p = nvdimm_provider_data(nvdimm);
261 600
@@ -277,7 +616,13 @@ static int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc, · 15 unmodified lines
277 *cmd_rc = papr_scm_meta_set(p, buf);616 *cmd_rc = papr_scm_meta_set(p, buf);
278 break;617 break;
279 618
619 case ND_CMD_CALL:
620 call_pkg = (struct nd_cmd_pkg *)buf;
621 *cmd_rc = papr_scm_service_pdsm(p, call_pkg);
622 break;
623
280 default:624 default:
625 dev_dbg(&p->pdev->dev, "Unknown command = %d\n", cmd);
281 return -EINVAL;626 return -EINVAL;
282 }627 }
283 628
@@ -286,6 +631,64 @@ static int papr_scm_ndctl(struct nvdimm_bus_descriptor *nd_desc, · 2 unmodified lines
286 return 0;631 return 0;
287}632}
288 633
634static ssize_t flags_show(struct device *dev,
635 struct device_attribute *attr, char *buf)
636{
637 struct nvdimm *dimm = to_nvdimm(dev);
638 struct papr_scm_priv *p = nvdimm_provider_data(dimm);
639 struct seq_buf s;
640 u64 health;
641 int rc;
642
643 rc = drc_pmem_query_health(p);
644 if (rc)
645 return rc;
646
647 /* Copy health_bitmap locally, check masks & update out buffer */
648 health = READ_ONCE(p->health_bitmap);
649
650 seq_buf_init(&s, buf, PAGE_SIZE);
651 if (health & PAPR_PMEM_UNARMED_MASK)
652 seq_buf_printf(&s, "not_armed ");
653
654 if (health & PAPR_PMEM_BAD_SHUTDOWN_MASK)
655 seq_buf_printf(&s, "flush_fail ");
656
657 if (health & PAPR_PMEM_BAD_RESTORE_MASK)
658 seq_buf_printf(&s, "restore_fail ");
659
660 if (health & PAPR_PMEM_ENCRYPTED)
661 seq_buf_printf(&s, "encrypted ");
662
663 if (health & PAPR_PMEM_SMART_EVENT_MASK)
664 seq_buf_printf(&s, "smart_notify ");
665
666 if (health & PAPR_PMEM_SCRUBBED_AND_LOCKED)
667 seq_buf_printf(&s, "scrubbed locked ");
668
669 if (seq_buf_used(&s))
670 seq_buf_printf(&s, "\n");
671
672 return seq_buf_used(&s);
673}
674DEVICE_ATTR_RO(flags);
675
676/* papr_scm specific dimm attributes */
677static struct attribute *papr_nd_attributes[] = {
678 &dev_attr_flags.attr,
679 NULL,
680};
681
682static struct attribute_group papr_nd_attribute_group = {
683 .name = "papr",
684 .attrs = papr_nd_attributes,
685};
686
687static const struct attribute_group *papr_nd_attr_groups[] = {
688 &papr_nd_attribute_group,
689 NULL,
690};
691
289static int papr_scm_nvdimm_init(struct papr_scm_priv *p)692static int papr_scm_nvdimm_init(struct papr_scm_priv *p)
290{693{
291 struct device *dev = &p->pdev->dev;694 struct device *dev = &p->pdev->dev;
@@ -312,8 +715,8 @@ static int papr_scm_nvdimm_init(struct papr_scm_priv *p) · 20 unmodified lines
312 dimm_flags = 0;715 dimm_flags = 0;
313 set_bit(NDD_LABELING, &dimm_flags);716 set_bit(NDD_LABELING, &dimm_flags);
314 717
315 p->nvdimm = nvdimm_create(p->bus, p, NULL, dimm_flags,718 p->nvdimm = nvdimm_create(p->bus, p, papr_nd_attr_groups,
316 PAPR_SCM_DIMM_CMD_MASK, 0, NULL);719 dimm_flags, PAPR_SCM_DIMM_CMD_MASK, 0, NULL);
317 if (!p->nvdimm) {720 if (!p->nvdimm) {
318 dev_err(dev, "Error creating DIMM object for %pOF\n", p->dn);721 dev_err(dev, "Error creating DIMM object for %pOF\n", p->dn);
319 goto err;722 goto err;
@@ -399,6 +802,9 @@ static int papr_scm_probe(struct platform_device *pdev) · 79 unmodified lines
399 if (!p)802 if (!p)
400 return -ENOMEM;803 return -ENOMEM;
401 804
805 /* Initialize the dimm mutex */
806 mutex_init(&p->health_mutex);
807
402 /* optional DT properties */808 /* optional DT properties */
403 of_property_read_u32(dn, "ibm,metadata-size", &metadata_size);809 of_property_read_u32(dn, "ibm,metadata-size", &metadata_size);
404 810
include/uapi/linux/ndctl.h+1−0
@@ -244,6 +244,7 @@ struct nd_cmd_pkg { · 243 unmodified lines
244#define NVDIMM_FAMILY_HPE2 2244#define NVDIMM_FAMILY_HPE2 2
245#define NVDIMM_FAMILY_MSFT 3245#define NVDIMM_FAMILY_MSFT 3
246#define NVDIMM_FAMILY_HYPERV 4246#define NVDIMM_FAMILY_HYPERV 4
247#define NVDIMM_FAMILY_PAPR 5
247 248
248#define ND_IOCTL_CALL _IOWR(ND_IOCTL, ND_CMD_CALL,\249#define ND_IOCTL_CALL _IOWR(ND_IOCTL, ND_CMD_CALL,\
249 struct nd_cmd_pkg)250 struct nd_cmd_pkg)
lib/seq_buf.c+1−0
@@ -91,6 +91,7 @@ int seq_buf_printf(struct seq_buf *s, const char *fmt, ...) · 90 unmodified lines
91 91
92 return ret;92 return ret;
93}93}
94EXPORT_SYMBOL_GPL(seq_buf_printf);
94 95
95#ifdef CONFIG_BINARY_PRINTF96#ifdef CONFIG_BINARY_PRINTF
96/**97/**