papr_pdsm_powerpc.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. #ifndef _ASM_POWERPC_PAPR_PDSM_H_
  10. #define _ASM_POWERPC_PAPR_PDSM_H_
  11. #include <linux/types.h>
  12. #include <linux/ndctl.h>
  13. /*
  14. * PDSM Envelope:
  15. *
  16. * The ioctl ND_CMD_CALL exchange data between user-space and kernel via
  17. * envelope which consists of 2 headers sections and payload sections as
  18. * illustrated below:
  19. * +-----------------+---------------+---------------------------+
  20. * | 64-Bytes | 8-Bytes | Max 184-Bytes |
  21. * +-----------------+---------------+---------------------------+
  22. * | ND-HEADER | PDSM-HEADER | PDSM-PAYLOAD |
  23. * +-----------------+---------------+---------------------------+
  24. * | nd_family | | |
  25. * | nd_size_out | cmd_status | |
  26. * | nd_size_in | reserved | nd_pdsm_payload |
  27. * | nd_command | payload --> | |
  28. * | nd_fw_size | | |
  29. * | nd_payload ---> | | |
  30. * +---------------+-----------------+---------------------------+
  31. *
  32. * ND Header:
  33. * This is the generic libnvdimm header described as 'struct nd_cmd_pkg'
  34. * which is interpreted by libnvdimm before passed on to papr_scm. Important
  35. * member fields used are:
  36. * 'nd_family' : (In) NVDIMM_FAMILY_PAPR_SCM
  37. * 'nd_size_in' : (In) PDSM-HEADER + PDSM-IN-PAYLOAD (usually 0)
  38. * 'nd_size_out' : (In) PDSM-HEADER + PDSM-RETURN-PAYLOAD
  39. * 'nd_command' : (In) One of PAPR_PDSM_XXX
  40. * 'nd_fw_size' : (Out) PDSM-HEADER + size of actual payload returned
  41. *
  42. * PDSM Header:
  43. * This is papr-scm specific header that precedes the payload. This is defined
  44. * as nd_cmd_pdsm_pkg. Following fields aare available in this header:
  45. *
  46. * 'cmd_status' : (Out) Errors if any encountered while servicing PDSM.
  47. * 'reserved' : Not used, reserved for future and should be set to 0.
  48. * 'payload' : A union of all the possible payload structs
  49. *
  50. * PDSM Payload:
  51. *
  52. * The layout of the PDSM Payload is defined by various structs shared between
  53. * papr_scm and libndctl so that contents of payload can be interpreted. As such
  54. * its defined as a union of all possible payload structs as
  55. * 'union nd_pdsm_payload'. Based on the value of 'nd_cmd_pkg.nd_command'
  56. * appropriate member of the union is accessed.
  57. */
  58. /* Max payload size that we can handle */
  59. #define ND_PDSM_PAYLOAD_MAX_SIZE 184
  60. /* Max payload size that we can handle */
  61. #define ND_PDSM_HDR_SIZE \
  62. (sizeof(struct nd_pkg_pdsm) - ND_PDSM_PAYLOAD_MAX_SIZE)
  63. /* Various nvdimm health indicators */
  64. #define PAPR_PDSM_DIMM_HEALTHY 0
  65. #define PAPR_PDSM_DIMM_UNHEALTHY 1
  66. #define PAPR_PDSM_DIMM_CRITICAL 2
  67. #define PAPR_PDSM_DIMM_FATAL 3
  68. /* struct nd_papr_pdsm_health.extension_flags field flags */
  69. /* Indicate that the 'dimm_fuel_gauge' field is valid */
  70. #define PDSM_DIMM_HEALTH_RUN_GAUGE_VALID 1
  71. /* Indicate that the 'dimm_dsc' field is valid */
  72. #define PDSM_DIMM_DSC_VALID 2
  73. /*
  74. * Struct exchanged between kernel & ndctl in for PAPR_PDSM_HEALTH
  75. * Various flags indicate the health status of the dimm.
  76. *
  77. * extension_flags : Any extension fields present in the struct.
  78. * dimm_unarmed : Dimm not armed. So contents wont persist.
  79. * dimm_bad_shutdown : Previous shutdown did not persist contents.
  80. * dimm_bad_restore : Contents from previous shutdown werent restored.
  81. * dimm_scrubbed : Contents of the dimm have been scrubbed.
  82. * dimm_locked : Contents of the dimm cant be modified until CEC reboot
  83. * dimm_encrypted : Contents of dimm are encrypted.
  84. * dimm_health : Dimm health indicator. One of PAPR_PDSM_DIMM_XXXX
  85. * dimm_fuel_gauge : Life remaining of DIMM as a percentage from 0-100
  86. */
  87. struct nd_papr_pdsm_health {
  88. union {
  89. struct {
  90. __u32 extension_flags;
  91. __u8 dimm_unarmed;
  92. __u8 dimm_bad_shutdown;
  93. __u8 dimm_bad_restore;
  94. __u8 dimm_scrubbed;
  95. __u8 dimm_locked;
  96. __u8 dimm_encrypted;
  97. __u16 dimm_health;
  98. /* Extension flag PDSM_DIMM_HEALTH_RUN_GAUGE_VALID */
  99. __u16 dimm_fuel_gauge;
  100. /* Extension flag PDSM_DIMM_DSC_VALID */
  101. __u64 dimm_dsc;
  102. };
  103. __u8 buf[ND_PDSM_PAYLOAD_MAX_SIZE];
  104. };
  105. };
  106. /* Flags for injecting specific smart errors */
  107. #define PDSM_SMART_INJECT_HEALTH_FATAL (1 << 0)
  108. #define PDSM_SMART_INJECT_BAD_SHUTDOWN (1 << 1)
  109. struct nd_papr_pdsm_smart_inject {
  110. union {
  111. struct {
  112. /* One or more of PDSM_SMART_INJECT_ */
  113. __u32 flags;
  114. __u8 fatal_enable;
  115. __u8 unsafe_shutdown_enable;
  116. };
  117. __u8 buf[ND_PDSM_PAYLOAD_MAX_SIZE];
  118. };
  119. };
  120. /*
  121. * Methods to be embedded in ND_CMD_CALL request. These are sent to the kernel
  122. * via 'nd_cmd_pkg.nd_command' member of the ioctl struct
  123. */
  124. enum papr_pdsm {
  125. PAPR_PDSM_MIN = 0x0,
  126. PAPR_PDSM_HEALTH,
  127. PAPR_PDSM_SMART_INJECT,
  128. PAPR_PDSM_MAX,
  129. };
  130. /* Maximal union that can hold all possible payload types */
  131. union nd_pdsm_payload {
  132. struct nd_papr_pdsm_health health;
  133. struct nd_papr_pdsm_smart_inject smart_inject;
  134. __u8 buf[ND_PDSM_PAYLOAD_MAX_SIZE];
  135. } __attribute__((packed));
  136. /*
  137. * PDSM-header + payload expected with ND_CMD_CALL ioctl from libnvdimm
  138. * Valid member of union 'payload' is identified via 'nd_cmd_pkg.nd_command'
  139. * that should always precede this struct when sent to papr_scm via CMD_CALL
  140. * interface.
  141. */
  142. struct nd_pkg_pdsm {
  143. __s32 cmd_status; /* Out: Sub-cmd status returned back */
  144. __u16 reserved[2]; /* Ignored and to be set as '0' */
  145. union nd_pdsm_payload payload;
  146. } __attribute__((packed));
  147. #endif /* _ASM_POWERPC_PAPR_PDSM_H_ */