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