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