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