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