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