projects/linux·blob assoc-array-fixes · refs

509 lines · 10.3 KiB

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