blob: b6e352cfe982b3d0ee905eef308b54771802f7b2 [file] [log] [blame]
Scott Bauer455a7b22017-02-03 12:50:31 -07001/*
2 * Copyright © 2016 Intel Corporation
3 *
4 * Authors:
5 * Rafael Antognolli <rafael.antognolli@intel.com>
6 * Scott Bauer <scott.bauer@intel.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 */
17#include <linux/types.h>
18
19#ifndef _OPAL_PROTO_H
20#define _OPAL_PROTO_H
21
Christoph Hellwig4f1244c2017-02-17 13:59:39 +010022/*
23 * These constant values come from:
24 * SPC-4 section
25 * 6.30 SECURITY PROTOCOL IN command / table 265.
26 */
27enum {
28 TCG_SECP_00 = 0,
29 TCG_SECP_01,
30};
31
32/*
33 * Token defs derived from:
34 * TCG_Storage_Architecture_Core_Spec_v2.01_r1.00
35 * 3.2.2 Data Stream Encoding
36 */
37enum opal_response_token {
38 OPAL_DTA_TOKENID_BYTESTRING = 0xe0,
39 OPAL_DTA_TOKENID_SINT = 0xe1,
40 OPAL_DTA_TOKENID_UINT = 0xe2,
41 OPAL_DTA_TOKENID_TOKEN = 0xe3, /* actual token is returned */
42 OPAL_DTA_TOKENID_INVALID = 0X0
43};
44
Scott Bauer455a7b22017-02-03 12:50:31 -070045#define DTAERROR_NO_METHOD_STATUS 0x89
46#define GENERIC_HOST_SESSION_NUM 0x41
47
48#define TPER_SYNC_SUPPORTED 0x01
Scott Bauerdbec491b2017-09-01 08:53:35 -060049#define MBR_ENABLED_MASK 0x10
Scott Bauer455a7b22017-02-03 12:50:31 -070050
51#define TINY_ATOM_DATA_MASK 0x3F
52#define TINY_ATOM_SIGNED 0x40
53
54#define SHORT_ATOM_ID 0x80
55#define SHORT_ATOM_BYTESTRING 0x20
56#define SHORT_ATOM_SIGNED 0x10
57#define SHORT_ATOM_LEN_MASK 0xF
58
59#define MEDIUM_ATOM_ID 0xC0
60#define MEDIUM_ATOM_BYTESTRING 0x10
61#define MEDIUM_ATOM_SIGNED 0x8
62#define MEDIUM_ATOM_LEN_MASK 0x7
63
64#define LONG_ATOM_ID 0xe0
65#define LONG_ATOM_BYTESTRING 0x2
66#define LONG_ATOM_SIGNED 0x1
67
68/* Derived from TCG Core spec 2.01 Section:
69 * 3.2.2.1
70 * Data Type
71 */
72#define TINY_ATOM_BYTE 0x7F
73#define SHORT_ATOM_BYTE 0xBF
74#define MEDIUM_ATOM_BYTE 0xDF
75#define LONG_ATOM_BYTE 0xE3
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_UID_LENGTH 8
88#define OPAL_METHOD_LENGTH 8
89#define OPAL_MSID_KEYLEN 15
90#define OPAL_UID_LENGTH_HALF 4
91
92/* Enum to index OPALUID array */
93enum opal_uid {
94 /* users */
95 OPAL_SMUID_UID,
96 OPAL_THISSP_UID,
97 OPAL_ADMINSP_UID,
98 OPAL_LOCKINGSP_UID,
99 OPAL_ENTERPRISE_LOCKINGSP_UID,
100 OPAL_ANYBODY_UID,
101 OPAL_SID_UID,
102 OPAL_ADMIN1_UID,
103 OPAL_USER1_UID,
104 OPAL_USER2_UID,
105 OPAL_PSID_UID,
106 OPAL_ENTERPRISE_BANDMASTER0_UID,
107 OPAL_ENTERPRISE_ERASEMASTER_UID,
108 /* tables */
109 OPAL_LOCKINGRANGE_GLOBAL,
110 OPAL_LOCKINGRANGE_ACE_RDLOCKED,
111 OPAL_LOCKINGRANGE_ACE_WRLOCKED,
112 OPAL_MBRCONTROL,
113 OPAL_MBR,
114 OPAL_AUTHORITY_TABLE,
115 OPAL_C_PIN_TABLE,
116 OPAL_LOCKING_INFO_TABLE,
117 OPAL_ENTERPRISE_LOCKING_INFO_TABLE,
118 /* C_PIN_TABLE object ID's */
119 OPAL_C_PIN_MSID,
120 OPAL_C_PIN_SID,
121 OPAL_C_PIN_ADMIN1,
122 /* half UID's (only first 4 bytes used) */
123 OPAL_HALF_UID_AUTHORITY_OBJ_REF,
124 OPAL_HALF_UID_BOOLEAN_ACE,
125 /* omitted optional parameter */
126 OPAL_UID_HEXFF,
127};
128
129#define OPAL_METHOD_LENGTH 8
130
131/* Enum for indexing the OPALMETHOD array */
132enum opal_method {
133 OPAL_PROPERTIES,
134 OPAL_STARTSESSION,
135 OPAL_REVERT,
136 OPAL_ACTIVATE,
137 OPAL_EGET,
138 OPAL_ESET,
139 OPAL_NEXT,
140 OPAL_EAUTHENTICATE,
141 OPAL_GETACL,
142 OPAL_GENKEY,
143 OPAL_REVERTSP,
144 OPAL_GET,
145 OPAL_SET,
146 OPAL_AUTHENTICATE,
147 OPAL_RANDOM,
148 OPAL_ERASE,
149};
150
151enum opal_token {
152 /* Boolean */
153 OPAL_TRUE = 0x01,
154 OPAL_FALSE = 0x00,
155 OPAL_BOOLEAN_EXPR = 0x03,
156 /* cellblocks */
157 OPAL_TABLE = 0x00,
158 OPAL_STARTROW = 0x01,
159 OPAL_ENDROW = 0x02,
160 OPAL_STARTCOLUMN = 0x03,
161 OPAL_ENDCOLUMN = 0x04,
162 OPAL_VALUES = 0x01,
163 /* authority table */
164 OPAL_PIN = 0x03,
165 /* locking tokens */
166 OPAL_RANGESTART = 0x03,
167 OPAL_RANGELENGTH = 0x04,
168 OPAL_READLOCKENABLED = 0x05,
169 OPAL_WRITELOCKENABLED = 0x06,
170 OPAL_READLOCKED = 0x07,
171 OPAL_WRITELOCKED = 0x08,
172 OPAL_ACTIVEKEY = 0x0A,
David Kozuba4ddbd12019-02-14 01:16:03 +0100173 /* lockingsp table */
174 OPAL_LIFECYCLE = 0x06,
Scott Bauer455a7b22017-02-03 12:50:31 -0700175 /* locking info table */
176 OPAL_MAXRANGES = 0x04,
177 /* mbr control */
178 OPAL_MBRENABLE = 0x01,
179 OPAL_MBRDONE = 0x02,
180 /* properties */
181 OPAL_HOSTPROPERTIES = 0x00,
182 /* atoms */
183 OPAL_STARTLIST = 0xf0,
184 OPAL_ENDLIST = 0xf1,
185 OPAL_STARTNAME = 0xf2,
186 OPAL_ENDNAME = 0xf3,
187 OPAL_CALL = 0xf8,
188 OPAL_ENDOFDATA = 0xf9,
189 OPAL_ENDOFSESSION = 0xfa,
190 OPAL_STARTTRANSACTON = 0xfb,
191 OPAL_ENDTRANSACTON = 0xfC,
192 OPAL_EMPTYATOM = 0xff,
193 OPAL_WHERE = 0x00,
194};
195
196/* Locking state for a locking range */
197enum opal_lockingstate {
198 OPAL_LOCKING_READWRITE = 0x01,
199 OPAL_LOCKING_READONLY = 0x02,
200 OPAL_LOCKING_LOCKED = 0x03,
201};
202
203/* Packets derived from:
204 * TCG_Storage_Architecture_Core_Spec_v2.01_r1.00
205 * Secion: 3.2.3 ComPackets, Packets & Subpackets
206 */
207
208/* Comm Packet (header) for transmissions. */
209struct opal_compacket {
210 __be32 reserved0;
211 u8 extendedComID[4];
212 __be32 outstandingData;
213 __be32 minTransfer;
214 __be32 length;
215};
216
217/* Packet structure. */
218struct opal_packet {
219 __be32 tsn;
220 __be32 hsn;
221 __be32 seq_number;
222 __be16 reserved0;
223 __be16 ack_type;
224 __be32 acknowledgment;
225 __be32 length;
226};
227
228/* Data sub packet header */
229struct opal_data_subpacket {
230 u8 reserved0[6];
231 __be16 kind;
232 __be32 length;
233};
234
235/* header of a response */
236struct opal_header {
237 struct opal_compacket cp;
238 struct opal_packet pkt;
239 struct opal_data_subpacket subpkt;
240};
241
242#define FC_TPER 0x0001
243#define FC_LOCKING 0x0002
244#define FC_GEOMETRY 0x0003
245#define FC_ENTERPRISE 0x0100
246#define FC_DATASTORE 0x0202
247#define FC_SINGLEUSER 0x0201
248#define FC_OPALV100 0x0200
249#define FC_OPALV200 0x0203
250
251/*
252 * The Discovery 0 Header. As defined in
253 * Opal SSC Documentation
254 * Section: 3.3.5 Capability Discovery
255 */
256struct d0_header {
257 __be32 length; /* the length of the header 48 in 2.00.100 */
258 __be32 revision; /**< revision of the header 1 in 2.00.100 */
259 __be32 reserved01;
260 __be32 reserved02;
261 /*
262 * the remainder of the structure is vendor specific and will not be
263 * addressed now
264 */
265 u8 ignored[32];
266};
267
268/*
269 * TPer Feature Descriptor. Contains flags indicating support for the
270 * TPer features described in the OPAL specification. The names match the
271 * OPAL terminology
272 *
273 * code == 0x001 in 2.00.100
274 */
275struct d0_tper_features {
276 /*
277 * supported_features bits:
278 * bit 7: reserved
279 * bit 6: com ID management
280 * bit 5: reserved
281 * bit 4: streaming support
282 * bit 3: buffer management
283 * bit 2: ACK/NACK
284 * bit 1: async
285 * bit 0: sync
286 */
287 u8 supported_features;
288 /*
289 * bytes 5 through 15 are reserved, but we represent the first 3 as
290 * u8 to keep the other two 32bits integers aligned.
291 */
292 u8 reserved01[3];
293 __be32 reserved02;
294 __be32 reserved03;
295};
296
297/*
298 * Locking Feature Descriptor. Contains flags indicating support for the
299 * locking features described in the OPAL specification. The names match the
300 * OPAL terminology
301 *
302 * code == 0x0002 in 2.00.100
303 */
304struct d0_locking_features {
305 /*
306 * supported_features bits:
307 * bits 6-7: reserved
308 * bit 5: MBR done
309 * bit 4: MBR enabled
310 * bit 3: media encryption
311 * bit 2: locked
312 * bit 1: locking enabled
313 * bit 0: locking supported
314 */
315 u8 supported_features;
316 /*
317 * bytes 5 through 15 are reserved, but we represent the first 3 as
318 * u8 to keep the other two 32bits integers aligned.
319 */
320 u8 reserved01[3];
321 __be32 reserved02;
322 __be32 reserved03;
323};
324
325/*
326 * Geometry Feature Descriptor. Contains flags indicating support for the
327 * geometry features described in the OPAL specification. The names match the
328 * OPAL terminology
329 *
330 * code == 0x0003 in 2.00.100
331 */
332struct d0_geometry_features {
333 /*
334 * skip 32 bits from header, needed to align the struct to 64 bits.
335 */
336 u8 header[4];
337 /*
338 * reserved01:
339 * bits 1-6: reserved
340 * bit 0: align
341 */
342 u8 reserved01;
343 u8 reserved02[7];
344 __be32 logical_block_size;
345 __be64 alignment_granularity;
346 __be64 lowest_aligned_lba;
347};
348
349/*
350 * Enterprise SSC Feature
351 *
352 * code == 0x0100
353 */
354struct d0_enterprise_ssc {
355 __be16 baseComID;
356 __be16 numComIDs;
357 /* range_crossing:
358 * bits 1-6: reserved
359 * bit 0: range crossing
360 */
361 u8 range_crossing;
362 u8 reserved01;
363 __be16 reserved02;
364 __be32 reserved03;
365 __be32 reserved04;
366};
367
368/*
369 * Opal V1 feature
370 *
371 * code == 0x0200
372 */
373struct d0_opal_v100 {
374 __be16 baseComID;
375 __be16 numComIDs;
376};
377
378/*
379 * Single User Mode feature
380 *
381 * code == 0x0201
382 */
383struct d0_single_user_mode {
384 __be32 num_locking_objects;
385 /* reserved01:
386 * bit 0: any
387 * bit 1: all
388 * bit 2: policy
389 * bits 3-7: reserved
390 */
391 u8 reserved01;
392 u8 reserved02;
393 __be16 reserved03;
394 __be32 reserved04;
395};
396
397/*
398 * Additonal Datastores feature
399 *
400 * code == 0x0202
401 */
402struct d0_datastore_table {
403 __be16 reserved01;
404 __be16 max_tables;
405 __be32 max_size_tables;
406 __be32 table_size_alignment;
407};
408
409/*
410 * OPAL 2.0 feature
411 *
412 * code == 0x0203
413 */
414struct d0_opal_v200 {
415 __be16 baseComID;
416 __be16 numComIDs;
417 /* range_crossing:
418 * bits 1-6: reserved
419 * bit 0: range crossing
420 */
421 u8 range_crossing;
422 /* num_locking_admin_auth:
423 * not aligned to 16 bits, so use two u8.
424 * stored in big endian:
425 * 0: MSB
426 * 1: LSB
427 */
428 u8 num_locking_admin_auth[2];
429 /* num_locking_user_auth:
430 * not aligned to 16 bits, so use two u8.
431 * stored in big endian:
432 * 0: MSB
433 * 1: LSB
434 */
435 u8 num_locking_user_auth[2];
436 u8 initialPIN;
437 u8 revertedPIN;
438 u8 reserved01;
439 __be32 reserved02;
440};
441
442/* Union of features used to parse the discovery 0 response */
443struct d0_features {
444 __be16 code;
445 /*
446 * r_version bits:
447 * bits 4-7: version
448 * bits 0-3: reserved
449 */
450 u8 r_version;
451 u8 length;
452 u8 features[];
453};
454
455#endif /* _OPAL_PROTO_H */