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