2 * osd_protocol.h - OSD T10 standard C definitions.
4 * Copyright (C) 2008 Panasas Inc. All rights reserved.
7 * Boaz Harrosh <bharrosh@panasas.com>
8 * Benny Halevy <bhalevy@panasas.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
13 * This file contains types and constants that are defined by the protocol
14 * Note: All names and symbols are taken from the OSD standard's text.
16 #ifndef __OSD_PROTOCOL_H__
17 #define __OSD_PROTOCOL_H__
19 #include <linux/types.h>
20 #include <asm/unaligned.h>
21 #include <scsi/scsi.h>
24 OSDv1_ADDITIONAL_CDB_LENGTH
= 192,
25 OSDv1_TOTAL_CDB_LEN
= OSDv1_ADDITIONAL_CDB_LENGTH
+ 8,
28 /* Latest supported version */
29 OSDv2_ADDITIONAL_CDB_LENGTH
= 228,
30 OSD_ADDITIONAL_CDB_LENGTH
=
31 OSDv2_ADDITIONAL_CDB_LENGTH
,
32 OSD_TOTAL_CDB_LEN
= OSD_ADDITIONAL_CDB_LENGTH
+ 8,
35 OSD_SYSTEMID_LEN
= 20,
36 OSDv1_CRYPTO_KEYID_SIZE
= 20,
37 OSDv2_CRYPTO_KEYID_SIZE
= 32,
38 OSD_CRYPTO_KEYID_SIZE
= OSDv2_CRYPTO_KEYID_SIZE
,
39 OSD_CRYPTO_SEED_SIZE
= 4,
40 OSD_CRYPTO_NONCE_SIZE
= 12,
41 OSD_MAX_SENSE_LEN
= 252, /* from SPC-3 */
43 OSD_PARTITION_FIRST_ID
= 0x10000,
44 OSD_OBJECT_FIRST_ID
= 0x10000,
48 * osd2r03: 5.2.3 Caching control bits
50 enum osd_options_byte
{
51 OSD_CDB_FUA
= 0x08, /* Force Unit Access */
52 OSD_CDB_DPO
= 0x10, /* Disable Page Out */
56 * osd2r03: 5.2.5 Isolation.
57 * First 3 bits, V2-only.
58 * Also for attr 110h "default isolation method" at Root Information page
60 enum osd_options_byte_isolation
{
61 OSD_ISOLATION_DEFAULT
= 0,
62 OSD_ISOLATION_NONE
= 1,
63 OSD_ISOLATION_STRICT
= 2,
64 OSD_ISOLATION_RANGE
= 4,
65 OSD_ISOLATION_FUNCTIONAL
= 5,
66 OSD_ISOLATION_VENDOR
= 7,
70 * osd2r03: 6.8 FLUSH, FLUSH COLLECTION, FLUSH OSD, FLUSH PARTITION
72 enum osd_options_flush_scope_values
{
73 OSD_CDB_FLUSH_ALL
= 0,
74 OSD_CDB_FLUSH_ATTR_ONLY
= 1,
76 OSD_CDB_FLUSH_ALL_RECURSIVE
= 2,
78 OSD_CDB_FLUSH_ALL_RANGE
= 2,
81 /* osd2r03: 5.2.10 Timestamps control */
83 OSD_CDB_NORMAL_TIMESTAMPS
= 0,
84 OSD_CDB_BYPASS_TIMESTAMPS
= 0x7f,
88 * osd2r03: 5.2.4.1 Get and set attributes CDB format selection
89 * 2 bits at second nibble of command_specific_options byte
91 enum osd_attributes_mode
{
93 OSD_CDB_SET_ONE_ATTR
= 0x10,
95 OSD_CDB_GET_ATTR_PAGE_SET_ONE
= 0x20,
96 OSD_CDB_GET_SET_ATTR_LISTS
= 0x30,
98 OSD_CDB_GET_SET_ATTR_MASK
= 0x30,
102 * osd2r03: 4.14.5 Data-In and Data-Out buffer offsets
103 * byte offset = mantissa * (2^(exponent+8))
105 * unsigned mantissa: 28;
109 typedef __be32 __bitwise osd_cdb_offset
;
112 OSD_OFFSET_UNUSED
= 0xFFFFFFFF,
113 OSD_OFFSET_MAX_BITS
= 28,
115 OSDv1_OFFSET_MIN_SHIFT
= 8,
116 OSD_OFFSET_MIN_SHIFT
= 3,
117 OSD_OFFSET_MAX_SHIFT
= 16,
120 /* Return the smallest allowed encoded offset that contains @offset.
122 * The actual encoded offset returned is @offset + *padding.
123 * (up to max_shift, non-inclusive)
125 osd_cdb_offset
__osd_encode_offset(u64 offset
, unsigned *padding
,
126 int min_shift
, int max_shift
);
128 /* Minimum alignment is 256 bytes
129 * Note: Seems from std v1 that exponent can be from 0+8 to 0xE+8 (inclusive)
130 * which is 8 to 23 but IBM code restricts it to 16, so be it.
132 static inline osd_cdb_offset
osd_encode_offset_v1(u64 offset
, unsigned *padding
)
134 return __osd_encode_offset(offset
, padding
,
135 OSDv1_OFFSET_MIN_SHIFT
, OSD_OFFSET_MAX_SHIFT
);
138 /* Minimum 8 bytes alignment
139 * Same as v1 but since exponent can be signed than a less than
140 * 256 alignment can be reached with small offsets (<2GB)
142 static inline osd_cdb_offset
osd_encode_offset_v2(u64 offset
, unsigned *padding
)
144 return __osd_encode_offset(offset
, padding
,
145 OSD_OFFSET_MIN_SHIFT
, OSD_OFFSET_MAX_SHIFT
);
148 /* osd2r03: 5.2.1 Overview */
149 struct osd_cdb_head
{
150 struct scsi_varlen_cdb_hdr varlen_cdb
;
152 u8 command_specific_options
;
153 u8 timestamp_control
;
154 /*13*/ u8 reserved1
[3];
155 /*16*/ __be64 partition
;
156 /*24*/ __be64 object
;
157 /*32*/ union { /* V1 vs V2 alignment differences */
158 struct __osdv1_cdb_addr_len
{
159 /*32*/ __be32 list_identifier
;/* Rarely used */
160 /*36*/ __be64 length
;
161 /*44*/ __be64 start_address
;
164 struct __osdv2_cdb_addr_len
{
165 /* called allocation_length in some commands */
166 /*32*/ __be64 length
;
167 /*40*/ __be64 start_address
;
169 /*48*/ __be32 list_identifier
;/* Rarely used */
170 /* OSD2r05 5.2.5 CDB continuation length */
171 /*48*/ __be32 cdb_continuation_length
;
175 /*52*/ union { /* selected attributes mode Page/List/Single */
176 struct osd_attributes_page_mode
{
177 /*52*/ __be32 get_attr_page
;
178 /*56*/ __be32 get_attr_alloc_length
;
179 /*60*/ osd_cdb_offset get_attr_offset
;
181 /*64*/ __be32 set_attr_page
;
182 /*68*/ __be32 set_attr_id
;
183 /*72*/ __be32 set_attr_length
;
184 /*76*/ osd_cdb_offset set_attr_offset
;
185 /*80*/ } __packed attrs_page
;
187 struct osd_attributes_list_mode
{
188 /*52*/ __be32 get_attr_desc_bytes
;
189 /*56*/ osd_cdb_offset get_attr_desc_offset
;
191 /*60*/ __be32 get_attr_alloc_length
;
192 /*64*/ osd_cdb_offset get_attr_offset
;
194 /*68*/ __be32 set_attr_bytes
;
195 /*72*/ osd_cdb_offset set_attr_offset
;
197 /*80*/ } __packed attrs_list
;
199 /* osd2r03:5.2.4.2 Set one attribute value using CDB fields */
200 struct osd_attributes_cdb_mode
{
201 /*52*/ __be32 set_attr_page
;
202 /*56*/ __be32 set_attr_id
;
203 /*60*/ __be16 set_attr_len
;
204 /*62*/ u8 set_attr_val
[18];
205 /*80*/ } __packed attrs_cdb
;
206 /*52*/ u8 get_set_attributes_parameters
[28];
212 struct osdv1_security_parameters
{
213 /*160*/u8 integrity_check_value
[OSDv1_CRYPTO_KEYID_SIZE
];
214 /*180*/u8 request_nonce
[OSD_CRYPTO_NONCE_SIZE
];
215 /*192*/osd_cdb_offset data_in_integrity_check_offset
;
216 /*196*/osd_cdb_offset data_out_integrity_check_offset
;
221 struct osdv2_security_parameters
{
222 /*184*/u8 integrity_check_value
[OSDv2_CRYPTO_KEYID_SIZE
];
223 /*216*/u8 request_nonce
[OSD_CRYPTO_NONCE_SIZE
];
224 /*228*/osd_cdb_offset data_in_integrity_check_offset
;
225 /*232*/osd_cdb_offset data_out_integrity_check_offset
;
229 struct osd_security_parameters
{
231 struct osdv1_security_parameters v1
;
232 struct osdv2_security_parameters v2
;
237 struct osd_cdb_head h
;
238 u8 caps
[OSDv1_CAP_LEN
];
239 struct osdv1_security_parameters sec_params
;
243 struct osd_cdb_head h
;
244 u8 caps
[OSD_CAP_LEN
];
245 struct osdv2_security_parameters sec_params
;
252 u8 buff
[OSD_TOTAL_CDB_LEN
];
256 static inline struct osd_cdb_head
*osd_cdb_head(struct osd_cdb
*ocdb
)
258 return (struct osd_cdb_head
*)ocdb
->buff
;
261 /* define both version actions
262 * Ex name = FORMAT_OSD we have OSD_ACT_FORMAT_OSD && OSDv1_ACT_FORMAT_OSD
264 #define OSD_ACT___(Name, Num) \
265 OSD_ACT_##Name = __constant_cpu_to_be16(0x8880 + Num), \
266 OSDv1_ACT_##Name = __constant_cpu_to_be16(0x8800 + Num),
268 /* V2 only actions */
269 #define OSD_ACT_V2(Name, Num) \
270 OSD_ACT_##Name = __constant_cpu_to_be16(0x8880 + Num),
272 #define OSD_ACT_V1_V2(Name, Num1, Num2) \
273 OSD_ACT_##Name = __constant_cpu_to_be16(Num2), \
274 OSDv1_ACT_##Name = __constant_cpu_to_be16(Num1),
276 enum osd_service_actions
{
277 OSD_ACT_V2(OBJECT_STRUCTURE_CHECK
, 0x00)
278 OSD_ACT___(FORMAT_OSD
, 0x01)
279 OSD_ACT___(CREATE
, 0x02)
280 OSD_ACT___(LIST
, 0x03)
281 OSD_ACT_V2(PUNCH
, 0x04)
282 OSD_ACT___(READ
, 0x05)
283 OSD_ACT___(WRITE
, 0x06)
284 OSD_ACT___(APPEND
, 0x07)
285 OSD_ACT___(FLUSH
, 0x08)
286 OSD_ACT_V2(CLEAR
, 0x09)
287 OSD_ACT___(REMOVE
, 0x0A)
288 OSD_ACT___(CREATE_PARTITION
, 0x0B)
289 OSD_ACT___(REMOVE_PARTITION
, 0x0C)
290 OSD_ACT___(GET_ATTRIBUTES
, 0x0E)
291 OSD_ACT___(SET_ATTRIBUTES
, 0x0F)
292 OSD_ACT___(CREATE_AND_WRITE
, 0x12)
293 OSD_ACT___(CREATE_COLLECTION
, 0x15)
294 OSD_ACT___(REMOVE_COLLECTION
, 0x16)
295 OSD_ACT___(LIST_COLLECTION
, 0x17)
296 OSD_ACT___(SET_KEY
, 0x18)
297 OSD_ACT___(SET_MASTER_KEY
, 0x19)
298 OSD_ACT___(FLUSH_COLLECTION
, 0x1A)
299 OSD_ACT___(FLUSH_PARTITION
, 0x1B)
300 OSD_ACT___(FLUSH_OSD
, 0x1C)
302 OSD_ACT_V2(QUERY
, 0x20)
303 OSD_ACT_V2(REMOVE_MEMBER_OBJECTS
, 0x21)
304 OSD_ACT_V2(GET_MEMBER_ATTRIBUTES
, 0x22)
305 OSD_ACT_V2(SET_MEMBER_ATTRIBUTES
, 0x23)
306 OSD_ACT_V2(READ_MAP
, 0x31)
308 OSD_ACT_V1_V2(PERFORM_SCSI_COMMAND
, 0x8F7E, 0x8F7C)
309 OSD_ACT_V1_V2(SCSI_TASK_MANAGEMENT
, 0x8F7F, 0x8F7D)
310 /* 0x8F80 to 0x8FFF are Vendor specific */
313 /* osd2r03: 7.1.3.2 List entry format for retrieving attributes */
314 struct osd_attributes_list_attrid
{
320 * NOTE: v1: is not aligned.
322 struct osdv1_attributes_list_element
{
325 __be16 attr_bytes
; /* valid bytes at attr_val without padding */
330 * osd2r03: 7.1.3.3 List entry format for retrieved attributes and
331 * for setting attributes
332 * NOTE: v2 is 8-bytes aligned
334 struct osdv2_attributes_list_element
{
338 __be16 attr_bytes
; /* valid bytes at attr_val without padding */
343 OSDv1_ATTRIBUTES_ELEM_ALIGN
= 1,
344 OSD_ATTRIBUTES_ELEM_ALIGN
= 8,
348 OSD_ATTR_LIST_ALL_PAGES
= 0xFFFFFFFF,
349 OSD_ATTR_LIST_ALL_IN_PAGE
= 0xFFFFFFFF,
352 static inline unsigned osdv1_attr_list_elem_size(unsigned len
)
354 return ALIGN(len
+ sizeof(struct osdv1_attributes_list_element
),
355 OSDv1_ATTRIBUTES_ELEM_ALIGN
);
358 static inline unsigned osdv2_attr_list_elem_size(unsigned len
)
360 return ALIGN(len
+ sizeof(struct osdv2_attributes_list_element
),
361 OSD_ATTRIBUTES_ELEM_ALIGN
);
365 * osd2r03: 7.1.3 OSD attributes lists (Table 184) — List type values
367 enum osd_attr_list_types
{
368 OSD_ATTR_LIST_GET
= 0x1, /* descriptors only */
369 OSD_ATTR_LIST_SET_RETRIEVE
= 0x9, /*descriptors/values variable-length*/
370 OSD_V2_ATTR_LIST_MULTIPLE
= 0xE, /* ver2, Multiple Objects lists*/
371 OSD_V1_ATTR_LIST_CREATE_MULTIPLE
= 0xF,/*ver1, used by create_multple*/
374 /* osd2r03: 7.1.3.4 Multi-object retrieved attributes format */
375 struct osd_attributes_list_multi_header
{
377 u8 object_type
; /* object_type enum below */
380 /* followed by struct osd_attributes_list_element's */
383 struct osdv1_attributes_list_header
{
384 u8 type
; /* low 4-bit only */
386 __be16 list_bytes
; /* Initiator shall set to Zero. Only set by target */
388 * type=9 followed by struct osd_attributes_list_element's
389 * type=E followed by struct osd_attributes_list_multi_header's
393 static inline unsigned osdv1_list_size(struct osdv1_attributes_list_header
*h
)
395 return be16_to_cpu(h
->list_bytes
);
398 struct osdv2_attributes_list_header
{
399 u8 type
; /* lower 4-bits only */
401 /*4*/ __be32 list_bytes
; /* Initiator shall set to zero. Only set by target */
403 * type=9 followed by struct osd_attributes_list_element's
404 * type=E followed by struct osd_attributes_list_multi_header's
408 static inline unsigned osdv2_list_size(struct osdv2_attributes_list_header
*h
)
410 return be32_to_cpu(h
->list_bytes
);
414 * osd2r03: 6.15 LIST (Table 79) LIST command parameter data.
415 * for root_lstchg below
418 OSD_OBJ_ID_LIST_PAR
= 0x1, /* V1-only. Not used in V2 */
419 OSD_OBJ_ID_LIST_LSTCHG
= 0x2,
423 * osd2r03: 6.15.2 LIST command parameter data
424 * (Also for LIST COLLECTION)
426 struct osd_obj_id_list
{
427 __be64 list_bytes
; /* bytes in list excluding list_bytes (-8) */
428 __be64 continuation_id
;
429 __be32 list_identifier
;
432 __be64 object_ids
[0];
435 static inline bool osd_is_obj_list_done(struct osd_obj_id_list
*list
,
438 *is_changed
= (0 != (list
->root_lstchg
& OSD_OBJ_ID_LIST_LSTCHG
));
439 return 0 != list
->continuation_id
;
443 * osd2r03: 4.12.4.5 The ALLDATA security method
445 struct osd_data_out_integrity_info
{
447 __be64 set_attributes_bytes
;
448 __be64 get_attributes_bytes
;
449 __u8 integrity_check_value
[OSD_CRYPTO_KEYID_SIZE
];
452 /* Same osd_data_out_integrity_info is used for OSD2/OSD1. The only difference
453 * Is the sizeof the structure since in OSD1 the last array is smaller. Use
454 * below for version independent handling of this structure
456 static inline int osd_data_out_integrity_info_sizeof(bool is_ver1
)
458 return sizeof(struct osd_data_out_integrity_info
) -
459 (is_ver1
* (OSDv2_CRYPTO_KEYID_SIZE
- OSDv1_CRYPTO_KEYID_SIZE
));
462 struct osd_data_in_integrity_info
{
464 __be64 retrieved_attributes_bytes
;
465 __u8 integrity_check_value
[OSD_CRYPTO_KEYID_SIZE
];
468 /* Same osd_data_in_integrity_info is used for OSD2/OSD1. The only difference
469 * Is the sizeof the structure since in OSD1 the last array is smaller. Use
470 * below for version independent handling of this structure
472 static inline int osd_data_in_integrity_info_sizeof(bool is_ver1
)
474 return sizeof(struct osd_data_in_integrity_info
) -
475 (is_ver1
* (OSDv2_CRYPTO_KEYID_SIZE
- OSDv1_CRYPTO_KEYID_SIZE
));
478 struct osd_timestamp
{
479 u8 time
[6]; /* number of milliseconds since 1/1/1970 UT (big endian) */
481 /* FIXME: define helper functions to convert to/from osd time format */
484 * Capability & Security definitions
485 * osd2r03: 4.11.2.2 Capability format
486 * osd2r03: 5.2.8 Security parameters
489 struct osd_key_identifier
{
490 u8 id
[7]; /* if you know why 7 please email bharrosh@panasas.com */
493 /* for osd_capability.format */
495 OSD_SEC_CAP_FORMAT_NO_CAPS
= 0,
496 OSD_SEC_CAP_FORMAT_VER1
= 1,
497 OSD_SEC_CAP_FORMAT_VER2
= 2,
500 /* security_method */
509 OSD_SEC_OBJ_ROOT
= 0x1,
510 OSD_SEC_OBJ_PARTITION
= 0x2,
511 OSD_SEC_OBJ_COLLECTION
= 0x40,
512 OSD_SEC_OBJ_USER
= 0x80,
515 enum osd_capability_bit_masks
{
516 OSD_SEC_CAP_APPEND
= BIT(0),
517 OSD_SEC_CAP_OBJ_MGMT
= BIT(1),
518 OSD_SEC_CAP_REMOVE
= BIT(2),
519 OSD_SEC_CAP_CREATE
= BIT(3),
520 OSD_SEC_CAP_SET_ATTR
= BIT(4),
521 OSD_SEC_CAP_GET_ATTR
= BIT(5),
522 OSD_SEC_CAP_WRITE
= BIT(6),
523 OSD_SEC_CAP_READ
= BIT(7),
525 OSD_SEC_CAP_NONE1
= BIT(8),
526 OSD_SEC_CAP_NONE2
= BIT(9),
527 OSD_SEC_GBL_REM
= BIT(10), /*v2 only*/
528 OSD_SEC_CAP_QUERY
= BIT(11), /*v2 only*/
529 OSD_SEC_CAP_M_OBJECT
= BIT(12), /*v2 only*/
530 OSD_SEC_CAP_POL_SEC
= BIT(13),
531 OSD_SEC_CAP_GLOBAL
= BIT(14),
532 OSD_SEC_CAP_DEV_MGMT
= BIT(15),
535 /* for object_descriptor_type (hi nibble used) */
537 OSD_SEC_OBJ_DESC_NONE
= 0, /* Not allowed */
538 OSD_SEC_OBJ_DESC_OBJ
= 1 << 4, /* v1: also collection */
539 OSD_SEC_OBJ_DESC_PAR
= 2 << 4, /* also root */
540 OSD_SEC_OBJ_DESC_COL
= 3 << 4, /* v2 only */
544 * osd2r03:4.11.2.2 Capability format
546 struct osd_capability_head
{
547 u8 format
; /* low nibble */
548 u8 integrity_algorithm__key_version
; /* MAKE_BYTE(integ_alg, key_ver) */
551 /*04*/ struct osd_timestamp expiration_time
;
553 /*30*/ u8 discriminator
[12];
554 /*42*/ struct osd_timestamp object_created_time
;
555 /*48*/ u8 object_type
;
556 /*49*/ u8 permissions_bit_mask
[5];
558 /*55*/ u8 object_descriptor_type
; /* high nibble */
562 struct osdv1_cap_object_descriptor
{
565 /*56*/ __be32 policy_access_tag
;
566 /*60*/ __be64 allowed_partition_id
;
567 /*68*/ __be64 allowed_object_id
;
568 /*76*/ __be32 reserved
;
571 /*56*/ u8 object_descriptor
[24];
577 struct osd_cap_object_descriptor
{
580 /*56*/ __be32 allowed_attributes_access
;
581 /*60*/ __be32 policy_access_tag
;
582 /*64*/ __be16 boot_epoch
;
583 /*66*/ u8 reserved
[6];
584 /*72*/ __be64 allowed_partition_id
;
585 /*80*/ __be64 allowed_object_id
;
586 /*88*/ __be64 allowed_range_length
;
587 /*96*/ __be64 allowed_range_start
;
590 /*56*/ u8 object_descriptor
[48];
595 struct osdv1_capability
{
596 struct osd_capability_head h
;
597 struct osdv1_cap_object_descriptor od
;
600 struct osd_capability
{
601 struct osd_capability_head h
;
602 struct osd_cap_object_descriptor od
;
606 * osd_sec_set_caps - set cap-bits into the capabilities header
608 * @cap: The osd_capability_head to set cap bits to.
609 * @bit_mask: Use an ORed list of enum osd_capability_bit_masks values
611 * permissions_bit_mask is unaligned use below to set into caps
612 * in a version independent way
614 static inline void osd_sec_set_caps(struct osd_capability_head
*cap
,
618 *Note: The bits above are defined LE order this is because this way
619 * they can grow in the future to more then 16, and still retain
620 * there constant values.
622 put_unaligned_le16(bit_mask
, &cap
->permissions_bit_mask
);
625 #endif /* ndef __OSD_PROTOCOL_H__ */