Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright © 2016 Intel Corporation
0004  *
0005  * Authors:
0006  *    Rafael Antognolli <rafael.antognolli@intel.com>
0007  *    Scott  Bauer      <scott.bauer@intel.com>
0008  */
0009 #include <linux/types.h>
0010 
0011 #ifndef _OPAL_PROTO_H
0012 #define _OPAL_PROTO_H
0013 
0014 /*
0015  * These constant values come from:
0016  * SPC-4 section
0017  * 6.30 SECURITY PROTOCOL IN command / table 265.
0018  */
0019 enum {
0020     TCG_SECP_00 = 0,
0021     TCG_SECP_01,
0022 };
0023 
0024 /*
0025  * Token defs derived from:
0026  * TCG_Storage_Architecture_Core_Spec_v2.01_r1.00
0027  * 3.2.2 Data Stream Encoding
0028  */
0029 enum opal_response_token {
0030     OPAL_DTA_TOKENID_BYTESTRING = 0xe0,
0031     OPAL_DTA_TOKENID_SINT = 0xe1,
0032     OPAL_DTA_TOKENID_UINT = 0xe2,
0033     OPAL_DTA_TOKENID_TOKEN = 0xe3, /* actual token is returned */
0034     OPAL_DTA_TOKENID_INVALID = 0X0
0035 };
0036 
0037 #define DTAERROR_NO_METHOD_STATUS 0x89
0038 #define GENERIC_HOST_SESSION_NUM 0x41
0039 #define FIRST_TPER_SESSION_NUM  4096
0040 
0041 #define TPER_SYNC_SUPPORTED 0x01
0042 #define MBR_ENABLED_MASK 0x10
0043 
0044 #define TINY_ATOM_DATA_MASK 0x3F
0045 #define TINY_ATOM_SIGNED 0x40
0046 
0047 #define SHORT_ATOM_ID 0x80
0048 #define SHORT_ATOM_BYTESTRING 0x20
0049 #define SHORT_ATOM_SIGNED 0x10
0050 #define SHORT_ATOM_LEN_MASK 0xF
0051 
0052 #define MEDIUM_ATOM_ID 0xC0
0053 #define MEDIUM_ATOM_BYTESTRING 0x10
0054 #define MEDIUM_ATOM_SIGNED 0x8
0055 #define MEDIUM_ATOM_LEN_MASK 0x7
0056 
0057 #define LONG_ATOM_ID 0xe0
0058 #define LONG_ATOM_BYTESTRING 0x2
0059 #define LONG_ATOM_SIGNED 0x1
0060 
0061 /* Derived from TCG Core spec 2.01 Section:
0062  * 3.2.2.1
0063  * Data Type
0064  */
0065 #define TINY_ATOM_BYTE   0x7F
0066 #define SHORT_ATOM_BYTE  0xBF
0067 #define MEDIUM_ATOM_BYTE 0xDF
0068 #define LONG_ATOM_BYTE   0xE3
0069 
0070 #define OPAL_INVAL_PARAM 12
0071 #define OPAL_MANUFACTURED_INACTIVE 0x08
0072 #define OPAL_DISCOVERY_COMID 0x0001
0073 
0074 #define LOCKING_RANGE_NON_GLOBAL 0x03
0075 /*
0076  * User IDs used in the TCG storage SSCs
0077  * Derived from: TCG_Storage_Architecture_Core_Spec_v2.01_r1.00
0078  * Section: 6.3 Assigned UIDs
0079  */
0080 #define OPAL_METHOD_LENGTH 8
0081 #define OPAL_MSID_KEYLEN 15
0082 #define OPAL_UID_LENGTH_HALF 4
0083 
0084 /* Enum to index OPALUID array */
0085 enum opal_uid {
0086     /* users */
0087     OPAL_SMUID_UID,
0088     OPAL_THISSP_UID,
0089     OPAL_ADMINSP_UID,
0090     OPAL_LOCKINGSP_UID,
0091     OPAL_ENTERPRISE_LOCKINGSP_UID,
0092     OPAL_ANYBODY_UID,
0093     OPAL_SID_UID,
0094     OPAL_ADMIN1_UID,
0095     OPAL_USER1_UID,
0096     OPAL_USER2_UID,
0097     OPAL_PSID_UID,
0098     OPAL_ENTERPRISE_BANDMASTER0_UID,
0099     OPAL_ENTERPRISE_ERASEMASTER_UID,
0100     /* tables */
0101     OPAL_TABLE_TABLE,
0102     OPAL_LOCKINGRANGE_GLOBAL,
0103     OPAL_LOCKINGRANGE_ACE_RDLOCKED,
0104     OPAL_LOCKINGRANGE_ACE_WRLOCKED,
0105     OPAL_MBRCONTROL,
0106     OPAL_MBR,
0107     OPAL_AUTHORITY_TABLE,
0108     OPAL_C_PIN_TABLE,
0109     OPAL_LOCKING_INFO_TABLE,
0110     OPAL_ENTERPRISE_LOCKING_INFO_TABLE,
0111     OPAL_DATASTORE,
0112     /* C_PIN_TABLE object ID's */
0113     OPAL_C_PIN_MSID,
0114     OPAL_C_PIN_SID,
0115     OPAL_C_PIN_ADMIN1,
0116     /* half UID's (only first 4 bytes used) */
0117     OPAL_HALF_UID_AUTHORITY_OBJ_REF,
0118     OPAL_HALF_UID_BOOLEAN_ACE,
0119     /* omitted optional parameter */
0120     OPAL_UID_HEXFF,
0121 };
0122 
0123 /* Enum for indexing the OPALMETHOD array */
0124 enum opal_method {
0125     OPAL_PROPERTIES,
0126     OPAL_STARTSESSION,
0127     OPAL_REVERT,
0128     OPAL_ACTIVATE,
0129     OPAL_EGET,
0130     OPAL_ESET,
0131     OPAL_NEXT,
0132     OPAL_EAUTHENTICATE,
0133     OPAL_GETACL,
0134     OPAL_GENKEY,
0135     OPAL_REVERTSP,
0136     OPAL_GET,
0137     OPAL_SET,
0138     OPAL_AUTHENTICATE,
0139     OPAL_RANDOM,
0140     OPAL_ERASE,
0141 };
0142 
0143 enum opal_token {
0144     /* Boolean */
0145     OPAL_TRUE = 0x01,
0146     OPAL_FALSE = 0x00,
0147     OPAL_BOOLEAN_EXPR = 0x03,
0148     /* cellblocks */
0149     OPAL_TABLE = 0x00,
0150     OPAL_STARTROW = 0x01,
0151     OPAL_ENDROW = 0x02,
0152     OPAL_STARTCOLUMN = 0x03,
0153     OPAL_ENDCOLUMN = 0x04,
0154     OPAL_VALUES = 0x01,
0155     /* table table */
0156     OPAL_TABLE_UID = 0x00,
0157     OPAL_TABLE_NAME = 0x01,
0158     OPAL_TABLE_COMMON = 0x02,
0159     OPAL_TABLE_TEMPLATE = 0x03,
0160     OPAL_TABLE_KIND = 0x04,
0161     OPAL_TABLE_COLUMN = 0x05,
0162     OPAL_TABLE_COLUMNS = 0x06,
0163     OPAL_TABLE_ROWS = 0x07,
0164     OPAL_TABLE_ROWS_FREE = 0x08,
0165     OPAL_TABLE_ROW_BYTES = 0x09,
0166     OPAL_TABLE_LASTID = 0x0A,
0167     OPAL_TABLE_MIN = 0x0B,
0168     OPAL_TABLE_MAX = 0x0C,
0169     /* authority table */
0170     OPAL_PIN = 0x03,
0171     /* locking tokens */
0172     OPAL_RANGESTART = 0x03,
0173     OPAL_RANGELENGTH = 0x04,
0174     OPAL_READLOCKENABLED = 0x05,
0175     OPAL_WRITELOCKENABLED = 0x06,
0176     OPAL_READLOCKED = 0x07,
0177     OPAL_WRITELOCKED = 0x08,
0178     OPAL_ACTIVEKEY = 0x0A,
0179     /* lockingsp table */
0180     OPAL_LIFECYCLE = 0x06,
0181     /* locking info table */
0182     OPAL_MAXRANGES = 0x04,
0183     /* mbr control */
0184     OPAL_MBRENABLE = 0x01,
0185     OPAL_MBRDONE = 0x02,
0186     /* properties */
0187     OPAL_HOSTPROPERTIES = 0x00,
0188     /* atoms */
0189     OPAL_STARTLIST = 0xf0,
0190     OPAL_ENDLIST = 0xf1,
0191     OPAL_STARTNAME = 0xf2,
0192     OPAL_ENDNAME = 0xf3,
0193     OPAL_CALL = 0xf8,
0194     OPAL_ENDOFDATA = 0xf9,
0195     OPAL_ENDOFSESSION = 0xfa,
0196     OPAL_STARTTRANSACTON = 0xfb,
0197     OPAL_ENDTRANSACTON = 0xfC,
0198     OPAL_EMPTYATOM = 0xff,
0199     OPAL_WHERE = 0x00,
0200 };
0201 
0202 /* Locking state for a locking range */
0203 enum opal_lockingstate {
0204     OPAL_LOCKING_READWRITE = 0x01,
0205     OPAL_LOCKING_READONLY = 0x02,
0206     OPAL_LOCKING_LOCKED = 0x03,
0207 };
0208 
0209 enum opal_parameter {
0210     OPAL_SUM_SET_LIST = 0x060000,
0211 };
0212 
0213 /* Packets derived from:
0214  * TCG_Storage_Architecture_Core_Spec_v2.01_r1.00
0215  * Secion: 3.2.3 ComPackets, Packets & Subpackets
0216  */
0217 
0218 /* Comm Packet (header) for transmissions. */
0219 struct opal_compacket {
0220     __be32 reserved0;
0221     u8 extendedComID[4];
0222     __be32 outstandingData;
0223     __be32 minTransfer;
0224     __be32 length;
0225 };
0226 
0227 /* Packet structure. */
0228 struct opal_packet {
0229     __be32 tsn;
0230     __be32 hsn;
0231     __be32 seq_number;
0232     __be16 reserved0;
0233     __be16 ack_type;
0234     __be32 acknowledgment;
0235     __be32 length;
0236 };
0237 
0238 /* Data sub packet header */
0239 struct opal_data_subpacket {
0240     u8 reserved0[6];
0241     __be16 kind;
0242     __be32 length;
0243 };
0244 
0245 /* header of a response */
0246 struct opal_header {
0247     struct opal_compacket cp;
0248     struct opal_packet pkt;
0249     struct opal_data_subpacket subpkt;
0250 };
0251 
0252 #define FC_TPER       0x0001
0253 #define FC_LOCKING    0x0002
0254 #define FC_GEOMETRY   0x0003
0255 #define FC_ENTERPRISE 0x0100
0256 #define FC_DATASTORE  0x0202
0257 #define FC_SINGLEUSER 0x0201
0258 #define FC_OPALV100   0x0200
0259 #define FC_OPALV200   0x0203
0260 
0261 /*
0262  * The Discovery 0 Header. As defined in
0263  * Opal SSC Documentation
0264  * Section: 3.3.5 Capability Discovery
0265  */
0266 struct d0_header {
0267     __be32 length; /* the length of the header 48 in 2.00.100 */
0268     __be32 revision; /**< revision of the header 1 in 2.00.100 */
0269     __be32 reserved01;
0270     __be32 reserved02;
0271     /*
0272      * the remainder of the structure is vendor specific and will not be
0273      * addressed now
0274      */
0275     u8 ignored[32];
0276 };
0277 
0278 /*
0279  * TPer Feature Descriptor. Contains flags indicating support for the
0280  * TPer features described in the OPAL specification. The names match the
0281  * OPAL terminology
0282  *
0283  * code == 0x001 in 2.00.100
0284  */
0285 struct d0_tper_features {
0286     /*
0287      * supported_features bits:
0288      * bit 7: reserved
0289      * bit 6: com ID management
0290      * bit 5: reserved
0291      * bit 4: streaming support
0292      * bit 3: buffer management
0293      * bit 2: ACK/NACK
0294      * bit 1: async
0295      * bit 0: sync
0296      */
0297     u8 supported_features;
0298     /*
0299      * bytes 5 through 15 are reserved, but we represent the first 3 as
0300      * u8 to keep the other two 32bits integers aligned.
0301      */
0302     u8 reserved01[3];
0303     __be32 reserved02;
0304     __be32 reserved03;
0305 };
0306 
0307 /*
0308  * Locking Feature Descriptor. Contains flags indicating support for the
0309  * locking features described in the OPAL specification. The names match the
0310  * OPAL terminology
0311  *
0312  * code == 0x0002 in 2.00.100
0313  */
0314 struct d0_locking_features {
0315     /*
0316      * supported_features bits:
0317      * bits 6-7: reserved
0318      * bit 5: MBR done
0319      * bit 4: MBR enabled
0320      * bit 3: media encryption
0321      * bit 2: locked
0322      * bit 1: locking enabled
0323      * bit 0: locking supported
0324      */
0325     u8 supported_features;
0326     /*
0327      * bytes 5 through 15 are reserved, but we represent the first 3 as
0328      * u8 to keep the other two 32bits integers aligned.
0329      */
0330     u8 reserved01[3];
0331     __be32 reserved02;
0332     __be32 reserved03;
0333 };
0334 
0335 /*
0336  * Geometry Feature Descriptor. Contains flags indicating support for the
0337  * geometry features described in the OPAL specification. The names match the
0338  * OPAL terminology
0339  *
0340  * code == 0x0003 in 2.00.100
0341  */
0342 struct d0_geometry_features {
0343     /*
0344      * skip 32 bits from header, needed to align the struct to 64 bits.
0345      */
0346     u8 header[4];
0347     /*
0348      * reserved01:
0349      * bits 1-6: reserved
0350      * bit 0: align
0351      */
0352     u8 reserved01;
0353     u8 reserved02[7];
0354     __be32 logical_block_size;
0355     __be64 alignment_granularity;
0356     __be64 lowest_aligned_lba;
0357 };
0358 
0359 /*
0360  * Enterprise SSC Feature
0361  *
0362  * code == 0x0100
0363  */
0364 struct d0_enterprise_ssc {
0365     __be16 baseComID;
0366     __be16 numComIDs;
0367     /* range_crossing:
0368      * bits 1-6: reserved
0369      * bit 0: range crossing
0370      */
0371     u8 range_crossing;
0372     u8 reserved01;
0373     __be16 reserved02;
0374     __be32 reserved03;
0375     __be32 reserved04;
0376 };
0377 
0378 /*
0379  * Opal V1 feature
0380  *
0381  * code == 0x0200
0382  */
0383 struct d0_opal_v100 {
0384     __be16 baseComID;
0385     __be16 numComIDs;
0386 };
0387 
0388 /*
0389  * Single User Mode feature
0390  *
0391  * code == 0x0201
0392  */
0393 struct d0_single_user_mode {
0394     __be32 num_locking_objects;
0395     /* reserved01:
0396      * bit 0: any
0397      * bit 1: all
0398      * bit 2: policy
0399      * bits 3-7: reserved
0400      */
0401     u8 reserved01;
0402     u8 reserved02;
0403     __be16 reserved03;
0404     __be32 reserved04;
0405 };
0406 
0407 /*
0408  * Additonal Datastores feature
0409  *
0410  * code == 0x0202
0411  */
0412 struct d0_datastore_table {
0413     __be16 reserved01;
0414     __be16 max_tables;
0415     __be32 max_size_tables;
0416     __be32 table_size_alignment;
0417 };
0418 
0419 /*
0420  * OPAL 2.0 feature
0421  *
0422  * code == 0x0203
0423  */
0424 struct d0_opal_v200 {
0425     __be16 baseComID;
0426     __be16 numComIDs;
0427     /* range_crossing:
0428      * bits 1-6: reserved
0429      * bit 0: range crossing
0430      */
0431     u8 range_crossing;
0432     /* num_locking_admin_auth:
0433      * not aligned to 16 bits, so use two u8.
0434      * stored in big endian:
0435      * 0: MSB
0436      * 1: LSB
0437      */
0438     u8 num_locking_admin_auth[2];
0439     /* num_locking_user_auth:
0440      * not aligned to 16 bits, so use two u8.
0441      * stored in big endian:
0442      * 0: MSB
0443      * 1: LSB
0444      */
0445     u8 num_locking_user_auth[2];
0446     u8 initialPIN;
0447     u8 revertedPIN;
0448     u8 reserved01;
0449     __be32 reserved02;
0450 };
0451 
0452 /* Union of features used to parse the discovery 0 response */
0453 struct d0_features {
0454     __be16 code;
0455     /*
0456      * r_version bits:
0457      * bits 4-7: version
0458      * bits 0-3: reserved
0459      */
0460     u8 r_version;
0461     u8 length;
0462     u8 features[];
0463 };
0464 
0465 #endif /* _OPAL_PROTO_H */