blob: 5ebb0b303defd76ff20030ed7352ec38fc44c0a2 [file] [log] [blame]
Nikhil Potadeb669b6b2019-03-13 10:52:21 -07001#pragma once
2
3#include <stdint.h>
4#include <stdlib.h>
5
6// NVM Express Management Interface 1.0 section 3.2.1
7const uint8_t NVME_MI_MESSAGE_TYPE = 0x04;
8
9const uint8_t NVME_MI_MESSAGE_TYPE_MASK = 0x7F;
10
11// Indicates this is covered by an MCTP integrity check
12const uint8_t NVME_MI_MCTP_INTEGRITY_CHECK = (1 << 7);
13
14// Indicates whether this is a request or response
15const uint8_t NVME_MI_HDR_FLAG_ROR = (1 << 7);
16
17const uint8_t NVME_MI_HDR_FLAG_MSG_TYPE_MASK = 0x0F;
18const uint8_t NVME_MI_HDR_FLAG_MSG_TYPE_SHIFT = 3;
19
20const 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)
24const uint8_t NVME_MI_HEALTH_STATUS_POLL_MSG_MIN = 8;
25
26enum 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
34enum NVME_MI_HDR_COMMAND_SLOT
35{
36 NVME_MI_HDR_COMMAND_SLOT_0 = 0x00,
37 NVME_MI_HDR_COMMAND_SLOT_1 = 0x01,
38};
39
40enum 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
54enum 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
66const uint8_t NVME_MI_MSG_REQUEST_HEADER_SIZE = 16;
67struct 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
76struct 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
83const uint8_t NVME_MI_MSG_RESPONSE_HEADER_SIZE = 5;
84struct 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
92struct 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};