Nikhil Potade | b669b6b | 2019-03-13 10:52:21 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <stdint.h> |
| 4 | #include <stdlib.h> |
| 5 | |
| 6 | // NVM Express Management Interface 1.0 section 3.2.1 |
| 7 | const uint8_t NVME_MI_MESSAGE_TYPE = 0x04; |
| 8 | |
| 9 | const uint8_t NVME_MI_MESSAGE_TYPE_MASK = 0x7F; |
| 10 | |
| 11 | // Indicates this is covered by an MCTP integrity check |
| 12 | const uint8_t NVME_MI_MCTP_INTEGRITY_CHECK = (1 << 7); |
| 13 | |
| 14 | // Indicates whether this is a request or response |
| 15 | const uint8_t NVME_MI_HDR_FLAG_ROR = (1 << 7); |
| 16 | |
| 17 | const uint8_t NVME_MI_HDR_FLAG_MSG_TYPE_MASK = 0x0F; |
| 18 | const uint8_t NVME_MI_HDR_FLAG_MSG_TYPE_SHIFT = 3; |
| 19 | |
| 20 | const uint16_t NVME_MI_MSG_BUFFER_SIZE = 256; |
| 21 | |
| 22 | // Minimum length of health status poll response |
| 23 | // NMH + Status + NVMe-MI Command Response Message (NCRESP) |
| 24 | const uint8_t NVME_MI_HEALTH_STATUS_POLL_MSG_MIN = 8; |
| 25 | |
| 26 | enum NVME_MI_HDR_MESSAGE_TYPE |
| 27 | { |
| 28 | NVME_MI_HDR_MESSAGE_TYPE_CONTROL_PRIMITIVE = 0x00, |
| 29 | NVME_MI_HDR_MESSAGE_TYPE_MI_COMMAND = 0x01, |
| 30 | NVME_MI_HDR_MESSAGE_TYPE_MI_ADMIN_COMMAND = 0x02, |
| 31 | NVME_MI_HDR_MESSAGE_TYPE_PCIE_COMMAND = 0x04, |
| 32 | }; |
| 33 | |
| 34 | enum NVME_MI_HDR_COMMAND_SLOT |
| 35 | { |
| 36 | NVME_MI_HDR_COMMAND_SLOT_0 = 0x00, |
| 37 | NVME_MI_HDR_COMMAND_SLOT_1 = 0x01, |
| 38 | }; |
| 39 | |
| 40 | enum NVME_MI_HDR_STATUS |
| 41 | { |
| 42 | NVME_MI_HDR_STATUS_SUCCESS = 0x00, |
| 43 | NVME_MI_HDR_STATUS_MORE_PROCESSING_REQUIRED = 0x01, |
| 44 | NVME_MI_HDR_STATUS_INTERNAL_ERROR = 0x02, |
| 45 | NVME_MI_HDR_STATUS_INVALID_COMMAND_OPCODE = 0x03, |
| 46 | NVME_MI_HDR_STATUS_INVALID_PARAMETER = 0x04, |
| 47 | NVME_MI_HDR_STATUS_INVALID_COMMAND_SIZE = 0x05, |
| 48 | NVME_MI_HDR_STATUS_INVALID_COMMAND_INPUT_DATA_SIZE = 0x06, |
| 49 | NVME_MI_HDR_STATUS_ACCESS_DENIED = 0x07, |
| 50 | NVME_MI_HDR_STATUS_VPD_UPDATES_EXCEEDED = 0x20, |
| 51 | NVME_MI_HDR_STATUS_PCIE_INACCESSIBLE = 0x21, |
| 52 | }; |
| 53 | |
| 54 | enum NVME_MI_OPCODE |
| 55 | { |
| 56 | NVME_MI_OPCODE_READ_MI_DATA = 0x00, |
| 57 | NVME_MI_OPCODE_HEALTH_STATUS_POLL = 0x01, |
| 58 | NVME_MI_OPCODE_CONTROLLER_HEALTH_STATUS_POLL = 0x02, |
| 59 | NVME_MI_OPCODE_CONFIGURATION_GET = 0x03, |
| 60 | NVME_MI_OPCODE_CONFIGURATION_SET = 0x04, |
| 61 | NVME_MI_OPCODE_VPD_READ = 0x05, |
| 62 | NVME_MI_OPCODE_VPD_WRITE = 0x06, |
| 63 | NVME_MI_OPCODE_RESET = 0x07, |
| 64 | }; |
| 65 | |
| 66 | const uint8_t NVME_MI_MSG_REQUEST_HEADER_SIZE = 16; |
| 67 | struct nvme_mi_msg_request_header |
| 68 | { |
| 69 | uint8_t message_type; |
| 70 | uint8_t flags; |
| 71 | uint8_t opcode; |
| 72 | uint32_t dword0; |
| 73 | uint32_t dword1; |
| 74 | }; |
| 75 | |
| 76 | struct nvme_mi_msg_request |
| 77 | { |
| 78 | struct nvme_mi_msg_request_header header; |
| 79 | uint8_t request_data[128]; |
| 80 | size_t request_data_len; |
| 81 | }; |
| 82 | |
| 83 | const uint8_t NVME_MI_MSG_RESPONSE_HEADER_SIZE = 5; |
| 84 | struct nvme_mi_msg_response_header |
| 85 | { |
| 86 | uint8_t message_type; |
| 87 | uint8_t flags; |
| 88 | // Reserved bytes 2:3 |
| 89 | uint8_t status; |
| 90 | }; |
| 91 | |
| 92 | struct nvme_mi_controller_health |
| 93 | { |
| 94 | uint8_t nvm_subsystem_status; |
| 95 | uint8_t smart_warnings; |
| 96 | uint8_t composite_temperature; |
| 97 | uint8_t percent_used; |
| 98 | uint16_t composite_controller_status; |
| 99 | }; |