1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
3 * PAPR nvDimm Specific Methods (PDSM) and structs for libndctl
5 * (C) Copyright IBM 2020
7 * Author: Vaibhav Jain <vaibhav at linux.ibm.com>
10 #ifndef _UAPI_ASM_POWERPC_PAPR_PDSM_H_
11 #define _UAPI_ASM_POWERPC_PAPR_PDSM_H_
13 #include <linux/types.h>
14 #include <linux/ndctl.h>
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
22 * +-----------------+---------------+---------------------------+
23 * | 64-Bytes | 8-Bytes | Max 184-Bytes |
24 * +-----------------+---------------+---------------------------+
25 * | ND-HEADER | PDSM-HEADER | PDSM-PAYLOAD |
26 * +-----------------+---------------+---------------------------+
28 * | nd_size_out | cmd_status | |
29 * | nd_size_in | reserved | nd_pdsm_payload |
30 * | nd_command | payload --> | |
32 * | nd_payload ---> | | |
33 * +---------------+-----------------+---------------------------+
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
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:
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
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.
62 /* Max payload size that we can handle */
63 #define ND_PDSM_PAYLOAD_MAX_SIZE 184
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)
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
75 /* struct nd_papr_pdsm_health.extension_flags field flags */
77 /* Indicate that the 'dimm_fuel_gauge' field is valid */
78 #define PDSM_DIMM_HEALTH_RUN_GAUGE_VALID 1
80 /* Indicate that the 'dimm_dsc' field is valid */
81 #define PDSM_DIMM_DSC_VALID 2
84 * Struct exchanged between kernel & ndctl in for PAPR_PDSM_HEALTH
85 * Various flags indicate the health status of the dimm.
87 * extension_flags : Any extension fields present in the struct.
88 * dimm_unarmed : Dimm not armed. So contents wont persist.
89 * dimm_bad_shutdown : Previous shutdown did not persist contents.
90 * dimm_bad_restore : Contents from previous shutdown werent restored.
91 * dimm_scrubbed : Contents of the dimm have been scrubbed.
92 * dimm_locked : Contents of the dimm cant be modified until CEC reboot
93 * dimm_encrypted : Contents of dimm are encrypted.
94 * dimm_health : Dimm health indicator. One of PAPR_PDSM_DIMM_XXXX
95 * dimm_fuel_gauge : Life remaining of DIMM as a percentage from 0-100
97 struct nd_papr_pdsm_health
{
100 __u32 extension_flags
;
102 __u8 dimm_bad_shutdown
;
103 __u8 dimm_bad_restore
;
109 /* Extension flag PDSM_DIMM_HEALTH_RUN_GAUGE_VALID */
110 __u16 dimm_fuel_gauge
;
112 /* Extension flag PDSM_DIMM_DSC_VALID */
115 __u8 buf
[ND_PDSM_PAYLOAD_MAX_SIZE
];
119 /* Flags for injecting specific smart errors */
120 #define PDSM_SMART_INJECT_HEALTH_FATAL (1 << 0)
121 #define PDSM_SMART_INJECT_BAD_SHUTDOWN (1 << 1)
123 struct nd_papr_pdsm_smart_inject
{
126 /* One or more of PDSM_SMART_INJECT_ */
129 __u8 unsafe_shutdown_enable
;
131 __u8 buf
[ND_PDSM_PAYLOAD_MAX_SIZE
];
136 * Methods to be embedded in ND_CMD_CALL request. These are sent to the kernel
137 * via 'nd_cmd_pkg.nd_command' member of the ioctl struct
142 PAPR_PDSM_SMART_INJECT
,
146 /* Maximal union that can hold all possible payload types */
147 union nd_pdsm_payload
{
148 struct nd_papr_pdsm_health health
;
149 struct nd_papr_pdsm_smart_inject smart_inject
;
150 __u8 buf
[ND_PDSM_PAYLOAD_MAX_SIZE
];
154 * PDSM-header + payload expected with ND_CMD_CALL ioctl from libnvdimm
155 * Valid member of union 'payload' is identified via 'nd_cmd_pkg.nd_command'
156 * that should always precede this struct when sent to papr_scm via CMD_CALL
160 __s32 cmd_status
; /* Out: Sub-cmd status returned back */
161 __u16 reserved
[2]; /* Ignored and to be set as '0' */
162 union nd_pdsm_payload payload
;
165 #endif /* _UAPI_ASM_POWERPC_PAPR_PDSM_H_ */