1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright © 2016 Intel Corporation 4 * 5 * Authors: 6 * Rafael Antognolli <rafael.antognolli@intel.com> 7 * Scott Bauer <scott.bauer@intel.com> 8 */ 9 #include <linux/types.h> 10 11 #ifndef _OPAL_PROTO_H 12 #define _OPAL_PROTO_H 13 14 /* 15 * These constant values come from: 16 * SPC-4 section 17 * 6.30 SECURITY PROTOCOL IN command / table 265. 18 */ 19 enum { 20 TCG_SECP_00 = 0, 21 TCG_SECP_01, 22 }; 23 24 /* 25 * Token defs derived from: 26 * TCG_Storage_Architecture_Core_Spec_v2.01_r1.00 27 * 3.2.2 Data Stream Encoding 28 */ 29 enum opal_response_token { 30 OPAL_DTA_TOKENID_BYTESTRING = 0xe0, 31 OPAL_DTA_TOKENID_SINT = 0xe1, 32 OPAL_DTA_TOKENID_UINT = 0xe2, 33 OPAL_DTA_TOKENID_TOKEN = 0xe3, /* actual token is returned */ 34 OPAL_DTA_TOKENID_INVALID = 0X0 35 }; 36 37 #define DTAERROR_NO_METHOD_STATUS 0x89 38 #define GENERIC_HOST_SESSION_NUM 0x41 39 #define FIRST_TPER_SESSION_NUM 4096 40 41 #define TPER_SYNC_SUPPORTED 0x01 42 /* FC_LOCKING features */ 43 #define LOCKING_SUPPORTED_MASK 0x01 44 #define LOCKING_ENABLED_MASK 0x02 45 #define LOCKED_MASK 0x04 46 #define MBR_ENABLED_MASK 0x10 47 #define MBR_DONE_MASK 0x20 48 49 #define TINY_ATOM_DATA_MASK 0x3F 50 #define TINY_ATOM_SIGNED 0x40 51 52 #define SHORT_ATOM_ID 0x80 53 #define SHORT_ATOM_BYTESTRING 0x20 54 #define SHORT_ATOM_SIGNED 0x10 55 #define SHORT_ATOM_LEN_MASK 0xF 56 57 #define MEDIUM_ATOM_ID 0xC0 58 #define MEDIUM_ATOM_BYTESTRING 0x10 59 #define MEDIUM_ATOM_SIGNED 0x8 60 #define MEDIUM_ATOM_LEN_MASK 0x7 61 62 #define LONG_ATOM_ID 0xe0 63 #define LONG_ATOM_BYTESTRING 0x2 64 #define LONG_ATOM_SIGNED 0x1 65 66 /* Derived from TCG Core spec 2.01 Section: 67 * 3.2.2.1 68 * Data Type 69 */ 70 #define TINY_ATOM_BYTE 0x7F 71 #define SHORT_ATOM_BYTE 0xBF 72 #define MEDIUM_ATOM_BYTE 0xDF 73 #define LONG_ATOM_BYTE 0xE3 74 75 #define OPAL_INVAL_PARAM 12 76 #define OPAL_MANUFACTURED_INACTIVE 0x08 77 #define OPAL_DISCOVERY_COMID 0x0001 78 79 #define LOCKING_RANGE_NON_GLOBAL 0x03 80 /* 81 * User IDs used in the TCG storage SSCs 82 * Derived from: TCG_Storage_Architecture_Core_Spec_v2.01_r1.00 83 * Section: 6.3 Assigned UIDs 84 */ 85 #define OPAL_METHOD_LENGTH 8 86 #define OPAL_MSID_KEYLEN 15 87 #define OPAL_UID_LENGTH_HALF 4 88 89 /* 90 * Boolean operators from TCG Core spec 2.01 Section: 91 * 5.1.3.11 92 * Table 61 93 */ 94 #define OPAL_BOOLEAN_AND 0 95 #define OPAL_BOOLEAN_OR 1 96 #define OPAL_BOOLEAN_NOT 2 97 98 /* Enum to index OPALUID array */ 99 enum opal_uid { 100 /* users */ 101 OPAL_SMUID_UID, 102 OPAL_THISSP_UID, 103 OPAL_ADMINSP_UID, 104 OPAL_LOCKINGSP_UID, 105 OPAL_ENTERPRISE_LOCKINGSP_UID, 106 OPAL_ANYBODY_UID, 107 OPAL_SID_UID, 108 OPAL_ADMIN1_UID, 109 OPAL_USER1_UID, 110 OPAL_USER2_UID, 111 OPAL_PSID_UID, 112 OPAL_ENTERPRISE_BANDMASTER0_UID, 113 OPAL_ENTERPRISE_ERASEMASTER_UID, 114 /* tables */ 115 OPAL_TABLE_TABLE, 116 OPAL_LOCKINGRANGE_GLOBAL, 117 OPAL_LOCKINGRANGE_ACE_START_TO_KEY, 118 OPAL_LOCKINGRANGE_ACE_RDLOCKED, 119 OPAL_LOCKINGRANGE_ACE_WRLOCKED, 120 OPAL_MBRCONTROL, 121 OPAL_MBR, 122 OPAL_AUTHORITY_TABLE, 123 OPAL_C_PIN_TABLE, 124 OPAL_LOCKING_INFO_TABLE, 125 OPAL_ENTERPRISE_LOCKING_INFO_TABLE, 126 OPAL_DATASTORE, 127 /* C_PIN_TABLE object ID's */ 128 OPAL_C_PIN_MSID, 129 OPAL_C_PIN_SID, 130 OPAL_C_PIN_ADMIN1, 131 /* half UID's (only first 4 bytes used) */ 132 OPAL_HALF_UID_AUTHORITY_OBJ_REF, 133 OPAL_HALF_UID_BOOLEAN_ACE, 134 /* omitted optional parameter */ 135 OPAL_UID_HEXFF, 136 }; 137 138 /* Enum for indexing the OPALMETHOD array */ 139 enum opal_method { 140 OPAL_PROPERTIES, 141 OPAL_STARTSESSION, 142 OPAL_REVERT, 143 OPAL_ACTIVATE, 144 OPAL_EGET, 145 OPAL_ESET, 146 OPAL_NEXT, 147 OPAL_EAUTHENTICATE, 148 OPAL_GETACL, 149 OPAL_GENKEY, 150 OPAL_REVERTSP, 151 OPAL_GET, 152 OPAL_SET, 153 OPAL_AUTHENTICATE, 154 OPAL_RANDOM, 155 OPAL_ERASE, 156 }; 157 158 enum opal_token { 159 /* Boolean */ 160 OPAL_TRUE = 0x01, 161 OPAL_FALSE = 0x00, 162 OPAL_BOOLEAN_EXPR = 0x03, 163 /* cellblocks */ 164 OPAL_TABLE = 0x00, 165 OPAL_STARTROW = 0x01, 166 OPAL_ENDROW = 0x02, 167 OPAL_STARTCOLUMN = 0x03, 168 OPAL_ENDCOLUMN = 0x04, 169 OPAL_VALUES = 0x01, 170 /* table table */ 171 OPAL_TABLE_UID = 0x00, 172 OPAL_TABLE_NAME = 0x01, 173 OPAL_TABLE_COMMON = 0x02, 174 OPAL_TABLE_TEMPLATE = 0x03, 175 OPAL_TABLE_KIND = 0x04, 176 OPAL_TABLE_COLUMN = 0x05, 177 OPAL_TABLE_COLUMNS = 0x06, 178 OPAL_TABLE_ROWS = 0x07, 179 OPAL_TABLE_ROWS_FREE = 0x08, 180 OPAL_TABLE_ROW_BYTES = 0x09, 181 OPAL_TABLE_LASTID = 0x0A, 182 OPAL_TABLE_MIN = 0x0B, 183 OPAL_TABLE_MAX = 0x0C, 184 /* authority table */ 185 OPAL_PIN = 0x03, 186 /* locking tokens */ 187 OPAL_RANGESTART = 0x03, 188 OPAL_RANGELENGTH = 0x04, 189 OPAL_READLOCKENABLED = 0x05, 190 OPAL_WRITELOCKENABLED = 0x06, 191 OPAL_READLOCKED = 0x07, 192 OPAL_WRITELOCKED = 0x08, 193 OPAL_ACTIVEKEY = 0x0A, 194 /* lockingsp table */ 195 OPAL_LIFECYCLE = 0x06, 196 /* locking info table */ 197 OPAL_MAXRANGES = 0x04, 198 /* mbr control */ 199 OPAL_MBRENABLE = 0x01, 200 OPAL_MBRDONE = 0x02, 201 /* properties */ 202 OPAL_HOSTPROPERTIES = 0x00, 203 /* atoms */ 204 OPAL_STARTLIST = 0xf0, 205 OPAL_ENDLIST = 0xf1, 206 OPAL_STARTNAME = 0xf2, 207 OPAL_ENDNAME = 0xf3, 208 OPAL_CALL = 0xf8, 209 OPAL_ENDOFDATA = 0xf9, 210 OPAL_ENDOFSESSION = 0xfa, 211 OPAL_STARTTRANSACTON = 0xfb, 212 OPAL_ENDTRANSACTON = 0xfC, 213 OPAL_EMPTYATOM = 0xff, 214 OPAL_WHERE = 0x00, 215 }; 216 217 /* Locking state for a locking range */ 218 enum opal_lockingstate { 219 OPAL_LOCKING_READWRITE = 0x01, 220 OPAL_LOCKING_READONLY = 0x02, 221 OPAL_LOCKING_LOCKED = 0x03, 222 }; 223 224 enum opal_parameter { 225 OPAL_SUM_SET_LIST = 0x060000, 226 }; 227 228 enum opal_revertlsp { 229 OPAL_KEEP_GLOBAL_RANGE_KEY = 0x060000, 230 }; 231 232 /* Packets derived from: 233 * TCG_Storage_Architecture_Core_Spec_v2.01_r1.00 234 * Secion: 3.2.3 ComPackets, Packets & Subpackets 235 */ 236 237 /* Comm Packet (header) for transmissions. */ 238 struct opal_compacket { 239 __be32 reserved0; 240 u8 extendedComID[4]; 241 __be32 outstandingData; 242 __be32 minTransfer; 243 __be32 length; 244 }; 245 246 /* Packet structure. */ 247 struct opal_packet { 248 __be32 tsn; 249 __be32 hsn; 250 __be32 seq_number; 251 __be16 reserved0; 252 __be16 ack_type; 253 __be32 acknowledgment; 254 __be32 length; 255 }; 256 257 /* Data sub packet header */ 258 struct opal_data_subpacket { 259 u8 reserved0[6]; 260 __be16 kind; 261 __be32 length; 262 }; 263 264 /* header of a response */ 265 struct opal_header { 266 struct opal_compacket cp; 267 struct opal_packet pkt; 268 struct opal_data_subpacket subpkt; 269 }; 270 271 #define FC_TPER 0x0001 272 #define FC_LOCKING 0x0002 273 #define FC_GEOMETRY 0x0003 274 #define FC_ENTERPRISE 0x0100 275 #define FC_DATASTORE 0x0202 276 #define FC_SINGLEUSER 0x0201 277 #define FC_OPALV100 0x0200 278 #define FC_OPALV200 0x0203 279 280 /* 281 * The Discovery 0 Header. As defined in 282 * Opal SSC Documentation 283 * Section: 3.3.5 Capability Discovery 284 */ 285 struct d0_header { 286 __be32 length; /* the length of the header 48 in 2.00.100 */ 287 __be32 revision; /**< revision of the header 1 in 2.00.100 */ 288 __be32 reserved01; 289 __be32 reserved02; 290 /* 291 * the remainder of the structure is vendor specific and will not be 292 * addressed now 293 */ 294 u8 ignored[32]; 295 }; 296 297 /* 298 * TPer Feature Descriptor. Contains flags indicating support for the 299 * TPer features described in the OPAL specification. The names match the 300 * OPAL terminology 301 * 302 * code == 0x001 in 2.00.100 303 */ 304 struct d0_tper_features { 305 /* 306 * supported_features bits: 307 * bit 7: reserved 308 * bit 6: com ID management 309 * bit 5: reserved 310 * bit 4: streaming support 311 * bit 3: buffer management 312 * bit 2: ACK/NACK 313 * bit 1: async 314 * bit 0: sync 315 */ 316 u8 supported_features; 317 /* 318 * bytes 5 through 15 are reserved, but we represent the first 3 as 319 * u8 to keep the other two 32bits integers aligned. 320 */ 321 u8 reserved01[3]; 322 __be32 reserved02; 323 __be32 reserved03; 324 }; 325 326 /* 327 * Locking Feature Descriptor. Contains flags indicating support for the 328 * locking features described in the OPAL specification. The names match the 329 * OPAL terminology 330 * 331 * code == 0x0002 in 2.00.100 332 */ 333 struct d0_locking_features { 334 /* 335 * supported_features bits: 336 * bits 6-7: reserved 337 * bit 5: MBR done 338 * bit 4: MBR enabled 339 * bit 3: media encryption 340 * bit 2: locked 341 * bit 1: locking enabled 342 * bit 0: locking supported 343 */ 344 u8 supported_features; 345 /* 346 * bytes 5 through 15 are reserved, but we represent the first 3 as 347 * u8 to keep the other two 32bits integers aligned. 348 */ 349 u8 reserved01[3]; 350 __be32 reserved02; 351 __be32 reserved03; 352 }; 353 354 /* 355 * Geometry Feature Descriptor. Contains flags indicating support for the 356 * geometry features described in the OPAL specification. The names match the 357 * OPAL terminology 358 * 359 * code == 0x0003 in 2.00.100 360 */ 361 struct d0_geometry_features { 362 /* 363 * skip 32 bits from header, needed to align the struct to 64 bits. 364 */ 365 u8 header[4]; 366 /* 367 * reserved01: 368 * bits 1-6: reserved 369 * bit 0: align 370 */ 371 u8 reserved01; 372 u8 reserved02[7]; 373 __be32 logical_block_size; 374 __be64 alignment_granularity; 375 __be64 lowest_aligned_lba; 376 }; 377 378 /* 379 * Enterprise SSC Feature 380 * 381 * code == 0x0100 382 */ 383 struct d0_enterprise_ssc { 384 __be16 baseComID; 385 __be16 numComIDs; 386 /* range_crossing: 387 * bits 1-6: reserved 388 * bit 0: range crossing 389 */ 390 u8 range_crossing; 391 u8 reserved01; 392 __be16 reserved02; 393 __be32 reserved03; 394 __be32 reserved04; 395 }; 396 397 /* 398 * Opal V1 feature 399 * 400 * code == 0x0200 401 */ 402 struct d0_opal_v100 { 403 __be16 baseComID; 404 __be16 numComIDs; 405 }; 406 407 /* 408 * Single User Mode feature 409 * 410 * code == 0x0201 411 */ 412 struct d0_single_user_mode { 413 __be32 num_locking_objects; 414 /* reserved01: 415 * bit 0: any 416 * bit 1: all 417 * bit 2: policy 418 * bits 3-7: reserved 419 */ 420 u8 reserved01; 421 u8 reserved02; 422 __be16 reserved03; 423 __be32 reserved04; 424 }; 425 426 /* 427 * Additonal Datastores feature 428 * 429 * code == 0x0202 430 */ 431 struct d0_datastore_table { 432 __be16 reserved01; 433 __be16 max_tables; 434 __be32 max_size_tables; 435 __be32 table_size_alignment; 436 }; 437 438 /* 439 * OPAL 2.0 feature 440 * 441 * code == 0x0203 442 */ 443 struct d0_opal_v200 { 444 __be16 baseComID; 445 __be16 numComIDs; 446 /* range_crossing: 447 * bits 1-6: reserved 448 * bit 0: range crossing 449 */ 450 u8 range_crossing; 451 /* num_locking_admin_auth: 452 * not aligned to 16 bits, so use two u8. 453 * stored in big endian: 454 * 0: MSB 455 * 1: LSB 456 */ 457 u8 num_locking_admin_auth[2]; 458 /* num_locking_user_auth: 459 * not aligned to 16 bits, so use two u8. 460 * stored in big endian: 461 * 0: MSB 462 * 1: LSB 463 */ 464 u8 num_locking_user_auth[2]; 465 u8 initialPIN; 466 u8 revertedPIN; 467 u8 reserved01; 468 __be32 reserved02; 469 }; 470 471 /* Union of features used to parse the discovery 0 response */ 472 struct d0_features { 473 __be16 code; 474 /* 475 * r_version bits: 476 * bits 4-7: version 477 * bits 0-3: reserved 478 */ 479 u8 r_version; 480 u8 length; 481 u8 features[]; 482 }; 483 484 #endif /* _OPAL_PROTO_H */ 485