1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2019 Intel Corporation. 3 * All rights reserved. 4 */ 5 6 #ifndef SPDK_OPAL_SPEC_H 7 #define SPDK_OPAL_SPEC_H 8 9 #include "spdk/stdinc.h" 10 #include "spdk/assert.h" 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 /* 17 * TCG Storage Architecture Core Spec v2.01 r1.00 18 * 3.2.2.3 Tokens 19 */ 20 #define SPDK_TINY_ATOM_TYPE_MAX 0x7F 21 #define SPDK_SHORT_ATOM_TYPE_MAX 0xBF 22 #define SPDK_MEDIUM_ATOM_TYPE_MAX 0xDF 23 #define SPDK_LONG_ATOM_TYPE_MAX 0xE3 24 25 #define SPDK_TINY_ATOM_SIGN_FLAG 0x40 26 27 #define SPDK_TINY_ATOM_DATA_MASK 0x3F 28 29 #define SPDK_SHORT_ATOM_ID 0x80 30 #define SPDK_SHORT_ATOM_BYTESTRING_FLAG 0x20 31 #define SPDK_SHORT_ATOM_SIGN_FLAG 0x10 32 #define SPDK_SHORT_ATOM_LEN_MASK 0x0F 33 34 #define SPDK_MEDIUM_ATOM_ID 0xC0 35 #define SPDK_MEDIUM_ATOM_BYTESTRING_FLAG 0x10 36 37 #define SPDK_MEDIUM_ATOM_SIGN_FLAG 0x08 38 #define SPDK_MEDIUM_ATOM_LEN_MASK 0x07 39 40 #define SPDK_LONG_ATOM_ID 0xE0 41 #define SPDK_LONG_ATOM_BYTESTRING_FLAG 0x02 42 #define SPDK_LONG_ATOM_SIGN_FLAG 0x01 43 44 /* 45 * TCG Storage Architecture Core Spec v2.01 r1.00 46 * Table-26 ComID management 47 */ 48 #define LV0_DISCOVERY_COMID 0x01 49 50 /* 51 * TCG Storage Opal v2.01 r1.00 52 * 5.2.3 Type Table Modification 53 */ 54 #define OPAL_MANUFACTURED_INACTIVE 0x08 55 56 #define LOCKING_RANGE_NON_GLOBAL 0x03 57 58 #define SPDK_OPAL_MAX_PASSWORD_SIZE 32 /* in bytes */ 59 60 #define SPDK_OPAL_MAX_LOCKING_RANGE 8 /* maximum 8 ranges defined by spec */ 61 62 /* 63 * Feature Code 64 */ 65 enum spdk_lv0_discovery_feature_code { 66 /* 67 * TCG Storage Architecture Core Spec v2.01 r1.00 68 * 3.3.6 Level 0 Discovery 69 */ 70 FEATURECODE_TPER = 0x0001, 71 FEATURECODE_LOCKING = 0x0002, 72 73 /* 74 * Opal SSC 1.00 r3.00 Final 75 * 3.1.1.4 Opal SSC Feature 76 */ 77 FEATURECODE_OPALV100 = 0x0200, 78 79 /* 80 * TCG Storage Opal v2.01 r1.00 81 * 3.1.1.4 Geometry Reporting Feature 82 * 3.1.1.5 Opal SSC V2.00 Feature 83 */ 84 FEATURECODE_OPALV200 = 0x0203, 85 FEATURECODE_GEOMETRY = 0x0003, 86 87 /* 88 * TCG Storage Opal Feature Set Single User Mode v1.00 r2.00 89 * 4.2.1 Single User Mode Feature Descriptor 90 */ 91 FEATURECODE_SINGLEUSER = 0x0201, 92 93 /* 94 * TCG Storage Opal Feature Set Additional DataStore Tables v1.00 r1.00 95 * 4.1.1 DataStore Table Feature Descriptor 96 */ 97 FEATURECODE_DATASTORE = 0x0202, 98 }; 99 100 /* 101 * TCG Storage Architecture Core Spec v2.01 r1.00 102 * 5.1.4 Abstract Type 103 */ 104 enum spdk_opal_token { 105 /* boolean */ 106 SPDK_OPAL_TRUE = 0x01, 107 SPDK_OPAL_FALSE = 0x00, 108 109 /* cell_block 110 * 5.1.4.2.3 */ 111 SPDK_OPAL_TABLE = 0x00, 112 SPDK_OPAL_STARTROW = 0x01, 113 SPDK_OPAL_ENDROW = 0x02, 114 SPDK_OPAL_STARTCOLUMN = 0x03, 115 SPDK_OPAL_ENDCOLUMN = 0x04, 116 SPDK_OPAL_VALUES = 0x01, 117 118 /* C_PIN table 119 * 5.3.2.12 */ 120 SPDK_OPAL_PIN = 0x03, 121 122 /* locking table 123 * 5.7.2.2 */ 124 SPDK_OPAL_RANGESTART = 0x03, 125 SPDK_OPAL_RANGELENGTH = 0x04, 126 SPDK_OPAL_READLOCKENABLED = 0x05, 127 SPDK_OPAL_WRITELOCKENABLED = 0x06, 128 SPDK_OPAL_READLOCKED = 0x07, 129 SPDK_OPAL_WRITELOCKED = 0x08, 130 SPDK_OPAL_ACTIVEKEY = 0x0A, 131 132 /* locking info table */ 133 SPDK_OPAL_MAXRANGES = 0x04, 134 135 /* mbr control */ 136 SPDK_OPAL_MBRENABLE = 0x01, 137 SPDK_OPAL_MBRDONE = 0x02, 138 139 /* properties */ 140 SPDK_OPAL_HOSTPROPERTIES = 0x00, 141 142 /* control tokens */ 143 SPDK_OPAL_STARTLIST = 0xF0, 144 SPDK_OPAL_ENDLIST = 0xF1, 145 SPDK_OPAL_STARTNAME = 0xF2, 146 SPDK_OPAL_ENDNAME = 0xF3, 147 SPDK_OPAL_CALL = 0xF8, 148 SPDK_OPAL_ENDOFDATA = 0xF9, 149 SPDK_OPAL_ENDOFSESSION = 0xFA, 150 SPDK_OPAL_STARTTRANSACTON = 0xFB, 151 SPDK_OPAL_ENDTRANSACTON = 0xFC, 152 SPDK_OPAL_EMPTYATOM = 0xFF, 153 SPDK_OPAL_WHERE = 0x00, 154 155 /* life cycle */ 156 SPDK_OPAL_LIFECYCLE = 0x06, 157 158 /* Authority table */ 159 SPDK_OPAL_AUTH_ENABLE = 0x05, 160 161 /* ACE table */ 162 SPDK_OPAL_BOOLEAN_EXPR = 0x03, 163 }; 164 165 /* 166 * TCG Storage Architecture Core Spec v2.01 r1.00 167 * Table-39 Level0 Discovery Header Format 168 */ 169 struct spdk_opal_d0_hdr { 170 uint32_t length; 171 uint32_t revision; 172 uint32_t reserved_0; 173 uint32_t reserved_1; 174 uint8_t vendor_specfic[32]; 175 }; 176 SPDK_STATIC_ASSERT(sizeof(struct spdk_opal_d0_hdr) == 48, "Incorrect size"); 177 178 /* 179 * Level 0 Discovery Feature Header 180 */ 181 struct spdk_opal_d0_feat_hdr { 182 uint16_t code; 183 uint8_t reserved : 4; 184 uint8_t version : 4; 185 uint8_t length; 186 }; 187 SPDK_STATIC_ASSERT(sizeof(struct spdk_opal_d0_feat_hdr) == 4, "Incorrect size"); 188 189 190 /* 191 * TCG Storage Architecture Core Spec v2.01 r1.00 192 * Table-42 TPer Feature Descriptor 193 */ 194 struct __attribute__((packed)) spdk_opal_d0_tper_feat { 195 struct spdk_opal_d0_feat_hdr hdr; 196 uint8_t sync : 1; 197 uint8_t async : 1; 198 uint8_t acknack : 1; 199 uint8_t buffer_management : 1; 200 uint8_t streaming : 1; 201 uint8_t reserved_1 : 1; 202 uint8_t comid_management : 1; 203 uint8_t reserved_2 : 1; 204 205 uint8_t reserved_3[3]; 206 uint32_t reserved_4; 207 uint32_t reserved_5; 208 }; 209 SPDK_STATIC_ASSERT(sizeof(struct spdk_opal_d0_tper_feat) == 16, "Incorrect size"); 210 211 /* 212 * TCG Storage Architecture Core Spec v2.01 r1.00 213 * Table-43 Locking Feature Descriptor 214 */ 215 struct __attribute__((packed)) spdk_opal_d0_locking_feat { 216 struct spdk_opal_d0_feat_hdr hdr; 217 uint8_t locking_supported : 1; 218 uint8_t locking_enabled : 1; 219 uint8_t locked : 1; 220 uint8_t media_encryption : 1; 221 uint8_t mbr_enabled : 1; 222 uint8_t mbr_done : 1; 223 uint8_t reserved_1 : 1; 224 uint8_t reserved_2 : 1; 225 226 uint8_t reserved_3[3]; 227 uint32_t reserved_4; 228 uint32_t reserved_5; 229 }; 230 SPDK_STATIC_ASSERT(sizeof(struct spdk_opal_d0_locking_feat) == 16, "Incorrect size"); 231 232 /* 233 * TCG Storage Opal Feature Set Single User Mode v1.00 r2.00 234 * 4.2.1 Single User Mode Feature Descriptor 235 */ 236 struct __attribute__((packed)) spdk_opal_d0_single_user_mode_feat { 237 struct spdk_opal_d0_feat_hdr hdr; 238 uint32_t num_locking_objects; 239 uint8_t any : 1; 240 uint8_t all : 1; 241 uint8_t policy : 1; 242 uint8_t reserved_1 : 5; 243 244 uint8_t reserved_2; 245 uint16_t reserved_3; 246 uint32_t reserved_4; 247 }; 248 SPDK_STATIC_ASSERT(sizeof(struct spdk_opal_d0_single_user_mode_feat) == 16, "Incorrect size"); 249 250 /* 251 * TCG Storage Opal v2.01 r1.00 252 * 3.1.1.4 Geometry Reporting Feature 253 */ 254 struct __attribute__((packed)) spdk_opal_d0_geo_feat { 255 struct spdk_opal_d0_feat_hdr hdr; 256 uint8_t align : 1; 257 uint8_t reserved_1 : 7; 258 uint8_t reserved_2[7]; 259 uint32_t logical_block_size; 260 uint64_t alignment_granularity; 261 uint64_t lowest_aligned_lba; 262 }; 263 SPDK_STATIC_ASSERT(sizeof(struct spdk_opal_d0_geo_feat) == 32, "Incorrect size"); 264 265 /* 266 * TCG Storage Opal Feature Set Additional DataStore Tables v1.00 r1.00 267 * 4.1.1 DataStore Table Feature Descriptor 268 */ 269 struct __attribute__((packed)) spdk_opal_d0_datastore_feat { 270 struct spdk_opal_d0_feat_hdr hdr; 271 uint16_t reserved_1; 272 uint16_t max_tables; 273 uint32_t max_table_size; 274 uint32_t alignment; 275 }; 276 SPDK_STATIC_ASSERT(sizeof(struct spdk_opal_d0_datastore_feat) == 16, "Incorrect size"); 277 278 /* 279 * Opal SSC 1.00 r3.00 Final 280 * 3.1.1.4 Opal SSC Feature 281 */ 282 struct __attribute__((packed)) spdk_opal_d0_v100_feat { 283 struct spdk_opal_d0_feat_hdr hdr; 284 uint16_t base_comid; 285 uint16_t number_comids; 286 uint8_t range_crossing : 1; 287 288 uint8_t reserved_1 : 7; 289 uint8_t reserved_2; 290 uint16_t reserved_3; 291 uint32_t reserved_4; 292 uint32_t reserved_5; 293 }; 294 SPDK_STATIC_ASSERT(sizeof(struct spdk_opal_d0_v100_feat) == 20, "Incorrect size"); 295 296 /* 297 * TCG Storage Opal v2.01 r1.00 298 * 3.1.1.4 Geometry Reporting Feature 299 * 3.1.1.5 Opal SSC V2.00 Feature 300 */ 301 struct __attribute__((packed)) spdk_opal_d0_v200_feat { 302 struct spdk_opal_d0_feat_hdr hdr; 303 uint16_t base_comid; 304 uint16_t num_comids; 305 uint8_t range_crossing : 1; 306 uint8_t reserved_1 : 7; 307 uint16_t num_locking_admin_auth; /* Number of Locking SP Admin Authorities Supported */ 308 uint16_t num_locking_user_auth; 309 uint8_t initial_pin; 310 uint8_t reverted_pin; 311 312 uint8_t reserved_2; 313 uint32_t reserved_3; 314 }; 315 SPDK_STATIC_ASSERT(sizeof(struct spdk_opal_d0_v200_feat) == 20, "Incorrect size"); 316 317 /* 318 * TCG Storage Architecture Core Spec v2.01 r1.00 319 * 3.2.3 ComPackets, Packets & Subpackets 320 */ 321 322 /* CommPacket header format 323 * (big-endian) 324 */ 325 struct __attribute__((packed)) spdk_opal_compacket { 326 uint32_t reserved; 327 uint8_t comid[2]; 328 uint8_t extended_comid[2]; 329 uint32_t outstanding_data; 330 uint32_t min_transfer; 331 uint32_t length; 332 }; 333 SPDK_STATIC_ASSERT(sizeof(struct spdk_opal_compacket) == 20, "Incorrect size"); 334 335 /* packet header format */ 336 struct __attribute__((packed)) spdk_opal_packet { 337 uint32_t session_tsn; 338 uint32_t session_hsn; 339 uint32_t seq_number; 340 uint16_t reserved; 341 uint16_t ack_type; 342 uint32_t acknowledgment; 343 uint32_t length; 344 }; 345 SPDK_STATIC_ASSERT(sizeof(struct spdk_opal_packet) == 24, "Incorrect size"); 346 347 /* data subpacket header */ 348 struct __attribute__((packed)) spdk_opal_data_subpacket { 349 uint8_t reserved[6]; 350 uint16_t kind; 351 uint32_t length; 352 }; 353 SPDK_STATIC_ASSERT(sizeof(struct spdk_opal_data_subpacket) == 12, "Incorrect size"); 354 355 #ifdef __cplusplus 356 } 357 #endif 358 359 #endif 360