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