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