1 /* 2 * Copyright (c) 2016 The DragonFly Project. All rights reserved. 3 * 4 * This code is derived from software contributed to The DragonFly Project 5 * by Matthew Dillon <dillon@backplane.com> 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * 3. Neither the name of The DragonFly Project nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific, prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35 /* 36 * Get Log Page - Error Information (Log ID 01) (64 bytes) 37 */ 38 typedef struct { 39 uint64_t error_count; 40 uint16_t subq_id; 41 uint16_t cmd_id; 42 uint16_t status; 43 uint16_t param; 44 uint64_t lba; 45 uint32_t nsid; 46 uint8_t vendor; 47 uint8_t reserved29; 48 uint8_t reserved30; 49 uint8_t reserved31; 50 uint64_t csi; /* command specific information */ 51 uint8_t reserved40[24]; 52 } __packed nvme_log_error_data_t; 53 54 /* 55 * Get Log Page - Smart/ Health Information (Log ID 02) (512 bytes) 56 */ 57 typedef struct { 58 uint8_t crit_flags; 59 uint8_t comp_temp1; 60 uint8_t comp_temp2; 61 uint8_t spare_cap; /* normalized spare capacity 0-100 */ 62 uint8_t spare_thresh; /* event when cap falls below value */ 63 uint8_t rated_life; /* 0-100, may exceed capped at 255 */ 64 uint8_t reserved6[26]; 65 66 /* 16-byte fields lo, hi */ 67 uint64_t read_count[2]; /* in 512000 byte units */ 68 uint64_t write_count[2]; /* in 512000 byte units */ 69 uint64_t read_cmds[2]; 70 uint64_t write_cmds[2]; 71 uint64_t busy_time[2]; /* in minutes */ 72 uint64_t power_cycles[2]; 73 uint64_t powon_hours[2]; 74 uint64_t unsafe_shutdowns[2]; 75 uint64_t unrecoverable_errors[2]; 76 uint64_t error_log_entries[2]; 77 78 uint32_t warn_comp_temp_time; /* minutes temp > warn level */ 79 uint32_t crit_comp_temp_time; /* minutes temp > crit level */ 80 81 uint16_t temp_sensors[8]; /* sensors 1-8 in kelvin 0=unimp */ 82 83 uint8_t reserved216[296]; 84 } __packed nvme_log_smart_data_t; 85 86 #define NVME_SMART_CRF_BELOW_THRESH 0x01 87 #define NVME_SMART_CRF_ABOVE_THRESH 0x02 /* or below under-temp thresh*/ 88 #define NVME_SMART_CRF_UNRELIABLE 0x04 89 #define NVME_SMART_CRF_MEDIA_RO 0x08 90 #define NVME_SMART_CRF_VOLTL_BKUP_FAIL 0x10 91 #define NVME_SMART_CRF_RES20 0x20 92 #define NVME_SMART_CRF_RES40 0x40 93 #define NVME_SMART_CRF_RES80 0x80 94 95 /* 96 * Firmware Slot Information (Log ID 03) (512 bytes) 97 */ 98 typedef struct { 99 uint8_t flags; 100 uint8_t reserved1[7]; 101 uint64_t revision[7]; /* revision slot 1-7 */ 102 uint8_t reserved64[448]; 103 } __packed nvme_fw_slot_data_t; 104 105 #define NVME_FWSLOT_CRF_RESERVED_80 0x80 106 #define NVME_FWSLOT_CRF_FWNEXT_MASK 0x70 107 #define NVME_FWSLOT_CRF_RESERVED_08 0x08 108 #define NVME_FWSLOT_CRF_FWCURR_MASK 0x07 109 110 #define NVME_FWSLOT_CRF_FWNEXT_GET(data) \ 111 (((data) & NVME_FWSLOT_CRF_FWNEXT_MASK) >> 4) 112 #define NVME_FWSLOT_CRF_FWCURR_GET(data) \ 113 ((data) & NVME_FWSLOT_CRF_FWCURR_MASK) 114 115 /* 116 * Command Supported and Effects (Log ID 05) (4096 bytes) 117 * 118 * Iterates available admin and I/O commands, one command-effects data 119 * structure for each command, indexed by command id. 120 * 121 * CSE - Indicates whether command must be serialized (i.e. no other 122 * commands may be pending in the namespace or globally). 123 * 124 * CSUPP - Indicates that the command is supported by the controller 125 * (use for iteration skip). 126 */ 127 typedef struct { 128 uint32_t admin_cmds[256]; 129 uint32_t io_cmds[256]; 130 } __packed nvme_cmdeff_data_t; 131 132 #define NVME_CMDEFF_RESERVED19 0xFFF80000U 133 #define NVME_CMDEFF_CSE_MASK 0x00007000U 134 #define NVME_CMDEFF_RESERVED05 0x00000FE0U 135 #define NVME_CMDEFF_CCC 0x00000010U 136 #define NVME_CMDEFF_NIC 0x00000008U 137 #define NVME_CMDEFF_NCC 0x00000004U 138 #define NVME_CMDEFF_LBCC 0x00000002U 139 #define NVME_CMDEFF_CSUPP 0x00000001U 140 141 #define NVME_CMDEFF_CSE_NORM 0x00000000U 142 #define NVME_CMDEFF_CSE_NS_SERIALIZE 0x00001000U 143 #define NVME_CMDEFF_CSE_GLOB_SERIALIZE 0x00002000U 144 145 /* 146 * Reservation Notification (Log ID 0x80) (64 bytes) 147 */ 148 typedef struct { 149 uint64_t logpg_count; 150 uint8_t type; 151 uint8_t logpg_avail; 152 uint8_t reserved10[2]; 153 uint32_t nsid; 154 uint8_t reserved16[48]; 155 } __packed nvme_resnotify_data_t; 156 157 #define NVME_RESNOTIFY_EMPTY 0x00 158 #define NVME_RESNOTIFY_REG_PREEMPTED 0x01 159 #define NVME_RESNOTIFY_RES_RELEASED 0x02 160 #define NVME_RESNOTIFY_RES_PREEMPTED 0x03 161 /* 04-FF reserved */ 162 163 /* TYPE_CSS status */ 164 #define NVME_RESNOTIFY_INVALID 0x09 165