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