Linux Audio

Check our new training course

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