zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

papr_pdsm.h (5740B) - Raw


      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 _ASM_POWERPC_PAPR_PDSM_H_
     11 #define _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 /* struct nd_papr_pdsm_health.extension_flags field flags */
     76 
     77 /* Indicate that the 'dimm_fuel_gauge' field is valid */
     78 #define PDSM_DIMM_HEALTH_RUN_GAUGE_VALID 1
     79 
     80 /* Indicate that the 'dimm_dsc' field is valid */
     81 #define PDSM_DIMM_DSC_VALID 2
     82 
     83 /*
     84  * Struct exchanged between kernel & ndctl in for PAPR_PDSM_HEALTH
     85  * Various flags indicate the health status of the dimm.
     86  *
     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
     96  */
     97 struct nd_papr_pdsm_health {
     98 	union {
     99 		struct {
    100 			__u32 extension_flags;
    101 			__u8 dimm_unarmed;
    102 			__u8 dimm_bad_shutdown;
    103 			__u8 dimm_bad_restore;
    104 			__u8 dimm_scrubbed;
    105 			__u8 dimm_locked;
    106 			__u8 dimm_encrypted;
    107 			__u16 dimm_health;
    108 
    109 			/* Extension flag PDSM_DIMM_HEALTH_RUN_GAUGE_VALID */
    110 			__u16 dimm_fuel_gauge;
    111 
    112 			/* Extension flag PDSM_DIMM_DSC_VALID */
    113 			__u64 dimm_dsc;
    114 		};
    115 		__u8 buf[ND_PDSM_PAYLOAD_MAX_SIZE];
    116 	};
    117 };
    118 
    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)
    122 
    123 struct nd_papr_pdsm_smart_inject {
    124 	union {
    125 		struct {
    126 			/* One or more of PDSM_SMART_INJECT_ */
    127 			__u32 flags;
    128 			__u8 fatal_enable;
    129 			__u8 unsafe_shutdown_enable;
    130 		};
    131 		__u8 buf[ND_PDSM_PAYLOAD_MAX_SIZE];
    132 	};
    133 };
    134 
    135 /*
    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
    138  */
    139 enum papr_pdsm {
    140 	PAPR_PDSM_MIN = 0x0,
    141 	PAPR_PDSM_HEALTH,
    142 	PAPR_PDSM_SMART_INJECT,
    143 	PAPR_PDSM_MAX,
    144 };
    145 
    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];
    151 } __attribute__((packed));
    152 
    153 /*
    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
    157  * interface.
    158  */
    159 struct nd_pkg_pdsm {
    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;
    163 } __attribute__((packed));
    164 
    165 #endif /* _ASM_POWERPC_PAPR_PDSM_H_ */