blob: bbeceeb0e553e592f3a17cdae2e1f591566bbb04 [file] [log] [blame]
Boaz Harroshde258bf2009-01-25 16:54:10 +02001/*
2 * osd_protocol.h - OSD T10 standard C definitions.
3 *
4 * Copyright (C) 2008 Panasas Inc. All rights reserved.
5 *
6 * Authors:
7 * Boaz Harrosh <bharrosh@panasas.com>
8 * Benny Halevy <bhalevy@panasas.com>
9 *
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
12 *
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.
15 */
16#ifndef __OSD_PROTOCOL_H__
17#define __OSD_PROTOCOL_H__
18
19#include <linux/types.h>
20#include <asm/unaligned.h>
21#include <scsi/scsi.h>
22
23enum {
24 OSDv1_ADDITIONAL_CDB_LENGTH = 192,
25 OSDv1_TOTAL_CDB_LEN = OSDv1_ADDITIONAL_CDB_LENGTH + 8,
26 OSDv1_CAP_LEN = 80,
27 /* Latest supported version */
Boaz Harroshc6572c92009-01-25 17:09:40 +020028/* OSD_ADDITIONAL_CDB_LENGTH = 216,*/
29 OSD_ADDITIONAL_CDB_LENGTH =
30 OSDv1_ADDITIONAL_CDB_LENGTH, /* FIXME: Pete rev-001 sup */
31 OSD_TOTAL_CDB_LEN = OSD_ADDITIONAL_CDB_LENGTH + 8,
32/* OSD_CAP_LEN = 104,*/
33 OSD_CAP_LEN = OSDv1_CAP_LEN,/* FIXME: Pete rev-001 sup */
Boaz Harroshde258bf2009-01-25 16:54:10 +020034
35 OSD_SYSTEMID_LEN = 20,
Boaz Harroshf8d3a642009-04-19 19:13:39 +030036 OSDv1_CRYPTO_KEYID_SIZE = 20,
Boaz Harroshc6572c92009-01-25 17:09:40 +020037 /*FIXME: OSDv2_CRYPTO_KEYID_SIZE = 32,*/
Boaz Harroshf8d3a642009-04-19 19:13:39 +030038 OSDv2_CRYPTO_KEYID_SIZE = 20,
39 OSD_CRYPTO_KEYID_SIZE = OSDv2_CRYPTO_KEYID_SIZE,
Boaz Harroshde258bf2009-01-25 16:54:10 +020040 OSD_CRYPTO_SEED_SIZE = 4,
41 OSD_CRYPTO_NONCE_SIZE = 12,
42 OSD_MAX_SENSE_LEN = 252, /* from SPC-3 */
43
44 OSD_PARTITION_FIRST_ID = 0x10000,
45 OSD_OBJECT_FIRST_ID = 0x10000,
46};
47
48/* (osd-r10 5.2.4)
49 * osd2r03: 5.2.3 Caching control bits
50 */
51enum osd_options_byte {
52 OSD_CDB_FUA = 0x08, /* Force Unit Access */
53 OSD_CDB_DPO = 0x10, /* Disable Page Out */
54};
55
56/*
57 * osd2r03: 5.2.5 Isolation.
58 * First 3 bits, V2-only.
59 * Also for attr 110h "default isolation method" at Root Information page
60 */
61enum osd_options_byte_isolation {
62 OSD_ISOLATION_DEFAULT = 0,
63 OSD_ISOLATION_NONE = 1,
64 OSD_ISOLATION_STRICT = 2,
65 OSD_ISOLATION_RANGE = 4,
66 OSD_ISOLATION_FUNCTIONAL = 5,
67 OSD_ISOLATION_VENDOR = 7,
68};
69
70/* (osd-r10: 6.7)
71 * osd2r03: 6.8 FLUSH, FLUSH COLLECTION, FLUSH OSD, FLUSH PARTITION
72 */
73enum osd_options_flush_scope_values {
74 OSD_CDB_FLUSH_ALL = 0,
75 OSD_CDB_FLUSH_ATTR_ONLY = 1,
76
77 OSD_CDB_FLUSH_ALL_RECURSIVE = 2,
78 /* V2-only */
79 OSD_CDB_FLUSH_ALL_RANGE = 2,
80};
81
82/* osd2r03: 5.2.10 Timestamps control */
83enum {
84 OSD_CDB_NORMAL_TIMESTAMPS = 0,
85 OSD_CDB_BYPASS_TIMESTAMPS = 0x7f,
86};
87
88/* (osd-r10: 5.2.2.1)
89 * osd2r03: 5.2.4.1 Get and set attributes CDB format selection
90 * 2 bits at second nibble of command_specific_options byte
91 */
92enum osd_attributes_mode {
93 /* V2-only */
94 OSD_CDB_SET_ONE_ATTR = 0x10,
95
96 OSD_CDB_GET_ATTR_PAGE_SET_ONE = 0x20,
97 OSD_CDB_GET_SET_ATTR_LISTS = 0x30,
98
99 OSD_CDB_GET_SET_ATTR_MASK = 0x30,
100};
101
102/* (osd-r10: 4.12.5)
103 * osd2r03: 4.14.5 Data-In and Data-Out buffer offsets
104 * byte offset = mantissa * (2^(exponent+8))
105 * struct {
106 * unsigned mantissa: 28;
107 * int exponent: 04;
108 * }
109 */
110typedef __be32 __bitwise osd_cdb_offset;
111
112enum {
113 OSD_OFFSET_UNUSED = 0xFFFFFFFF,
114 OSD_OFFSET_MAX_BITS = 28,
115
116 OSDv1_OFFSET_MIN_SHIFT = 8,
Boaz Harroshc6572c92009-01-25 17:09:40 +0200117 OSD_OFFSET_MIN_SHIFT = 3,
Boaz Harroshde258bf2009-01-25 16:54:10 +0200118 OSD_OFFSET_MAX_SHIFT = 16,
119};
120
121/* Return the smallest allowed encoded offset that contains @offset.
122 *
123 * The actual encoded offset returned is @offset + *padding.
124 * (up to max_shift, non-inclusive)
125 */
126osd_cdb_offset __osd_encode_offset(u64 offset, unsigned *padding,
127 int min_shift, int max_shift);
128
129/* Minimum alignment is 256 bytes
130 * Note: Seems from std v1 that exponent can be from 0+8 to 0xE+8 (inclusive)
131 * which is 8 to 23 but IBM code restricts it to 16, so be it.
132 */
133static inline osd_cdb_offset osd_encode_offset_v1(u64 offset, unsigned *padding)
134{
135 return __osd_encode_offset(offset, padding,
136 OSDv1_OFFSET_MIN_SHIFT, OSD_OFFSET_MAX_SHIFT);
137}
138
Boaz Harroshc6572c92009-01-25 17:09:40 +0200139/* Minimum 8 bytes alignment
140 * Same as v1 but since exponent can be signed than a less than
141 * 256 alignment can be reached with small offsets (<2GB)
142 */
143static inline osd_cdb_offset osd_encode_offset_v2(u64 offset, unsigned *padding)
144{
145 return __osd_encode_offset(offset, padding,
146 OSD_OFFSET_MIN_SHIFT, OSD_OFFSET_MAX_SHIFT);
147}
148
Boaz Harroshde258bf2009-01-25 16:54:10 +0200149/* osd2r03: 5.2.1 Overview */
150struct osd_cdb_head {
151 struct scsi_varlen_cdb_hdr varlen_cdb;
152/*10*/ u8 options;
153 u8 command_specific_options;
154 u8 timestamp_control;
155/*13*/ u8 reserved1[3];
156/*16*/ __be64 partition;
157/*24*/ __be64 object;
158/*32*/ union { /* V1 vs V2 alignment differences */
159 struct __osdv1_cdb_addr_len {
160/*32*/ __be32 list_identifier;/* Rarely used */
161/*36*/ __be64 length;
162/*44*/ __be64 start_address;
163 } __packed v1;
Boaz Harroshc6572c92009-01-25 17:09:40 +0200164
165 struct __osdv2_cdb_addr_len {
166 /* called allocation_length in some commands */
167/*32*/ __be64 length;
168/*40*/ __be64 start_address;
169/*48*/ __be32 list_identifier;/* Rarely used */
170 } __packed v2;
Boaz Harroshde258bf2009-01-25 16:54:10 +0200171 };
172/*52*/ union { /* selected attributes mode Page/List/Single */
173 struct osd_attributes_page_mode {
174/*52*/ __be32 get_attr_page;
175/*56*/ __be32 get_attr_alloc_length;
176/*60*/ osd_cdb_offset get_attr_offset;
177
178/*64*/ __be32 set_attr_page;
179/*68*/ __be32 set_attr_id;
180/*72*/ __be32 set_attr_length;
181/*76*/ osd_cdb_offset set_attr_offset;
182/*80*/ } __packed attrs_page;
183
184 struct osd_attributes_list_mode {
185/*52*/ __be32 get_attr_desc_bytes;
186/*56*/ osd_cdb_offset get_attr_desc_offset;
187
188/*60*/ __be32 get_attr_alloc_length;
189/*64*/ osd_cdb_offset get_attr_offset;
190
191/*68*/ __be32 set_attr_bytes;
192/*72*/ osd_cdb_offset set_attr_offset;
193 __be32 not_used;
194/*80*/ } __packed attrs_list;
195
196 /* osd2r03:5.2.4.2 Set one attribute value using CDB fields */
197 struct osd_attributes_cdb_mode {
198/*52*/ __be32 set_attr_page;
199/*56*/ __be32 set_attr_id;
200/*60*/ __be16 set_attr_len;
201/*62*/ u8 set_attr_val[18];
202/*80*/ } __packed attrs_cdb;
203/*52*/ u8 get_set_attributes_parameters[28];
204 };
205} __packed;
206/*80*/
207
208/*160 v1*/
Boaz Harroshf8d3a642009-04-19 19:13:39 +0300209struct osdv1_security_parameters {
210/*160*/u8 integrity_check_value[OSDv1_CRYPTO_KEYID_SIZE];
Boaz Harroshde258bf2009-01-25 16:54:10 +0200211/*180*/u8 request_nonce[OSD_CRYPTO_NONCE_SIZE];
212/*192*/osd_cdb_offset data_in_integrity_check_offset;
213/*196*/osd_cdb_offset data_out_integrity_check_offset;
214} __packed;
215/*200 v1*/
Boaz Harroshc6572c92009-01-25 17:09:40 +0200216
Boaz Harroshf8d3a642009-04-19 19:13:39 +0300217/*184 v2*/
218struct osdv2_security_parameters {
219/*184*/u8 integrity_check_value[OSDv2_CRYPTO_KEYID_SIZE];
220/*216*/u8 request_nonce[OSD_CRYPTO_NONCE_SIZE];
221/*228*/osd_cdb_offset data_in_integrity_check_offset;
222/*232*/osd_cdb_offset data_out_integrity_check_offset;
223} __packed;
224/*236 v2*/
225
226struct osd_security_parameters {
227 union {
228 struct osdv1_security_parameters v1;
229 struct osdv2_security_parameters v2;
230 };
231};
Boaz Harroshde258bf2009-01-25 16:54:10 +0200232
233struct osdv1_cdb {
234 struct osd_cdb_head h;
235 u8 caps[OSDv1_CAP_LEN];
Boaz Harroshf8d3a642009-04-19 19:13:39 +0300236 struct osdv1_security_parameters sec_params;
Boaz Harroshde258bf2009-01-25 16:54:10 +0200237} __packed;
238
Boaz Harroshc6572c92009-01-25 17:09:40 +0200239struct osdv2_cdb {
240 struct osd_cdb_head h;
241 u8 caps[OSD_CAP_LEN];
Boaz Harroshf8d3a642009-04-19 19:13:39 +0300242 struct osdv2_security_parameters sec_params;
Boaz Harroshc6572c92009-01-25 17:09:40 +0200243} __packed;
244
Boaz Harroshde258bf2009-01-25 16:54:10 +0200245struct osd_cdb {
246 union {
247 struct osdv1_cdb v1;
Boaz Harroshc6572c92009-01-25 17:09:40 +0200248 struct osdv2_cdb v2;
Boaz Harroshde258bf2009-01-25 16:54:10 +0200249 u8 buff[OSD_TOTAL_CDB_LEN];
250 };
251} __packed;
252
253static inline struct osd_cdb_head *osd_cdb_head(struct osd_cdb *ocdb)
254{
255 return (struct osd_cdb_head *)ocdb->buff;
256}
257
258/* define both version actions
259 * Ex name = FORMAT_OSD we have OSD_ACT_FORMAT_OSD && OSDv1_ACT_FORMAT_OSD
260 */
261#define OSD_ACT___(Name, Num) \
262 OSD_ACT_##Name = __constant_cpu_to_be16(0x8880 + Num), \
263 OSDv1_ACT_##Name = __constant_cpu_to_be16(0x8800 + Num),
264
265/* V2 only actions */
266#define OSD_ACT_V2(Name, Num) \
267 OSD_ACT_##Name = __constant_cpu_to_be16(0x8880 + Num),
268
269#define OSD_ACT_V1_V2(Name, Num1, Num2) \
270 OSD_ACT_##Name = __constant_cpu_to_be16(Num2), \
271 OSDv1_ACT_##Name = __constant_cpu_to_be16(Num1),
272
273enum osd_service_actions {
274 OSD_ACT_V2(OBJECT_STRUCTURE_CHECK, 0x00)
275 OSD_ACT___(FORMAT_OSD, 0x01)
276 OSD_ACT___(CREATE, 0x02)
277 OSD_ACT___(LIST, 0x03)
278 OSD_ACT_V2(PUNCH, 0x04)
279 OSD_ACT___(READ, 0x05)
280 OSD_ACT___(WRITE, 0x06)
281 OSD_ACT___(APPEND, 0x07)
282 OSD_ACT___(FLUSH, 0x08)
283 OSD_ACT_V2(CLEAR, 0x09)
284 OSD_ACT___(REMOVE, 0x0A)
285 OSD_ACT___(CREATE_PARTITION, 0x0B)
286 OSD_ACT___(REMOVE_PARTITION, 0x0C)
287 OSD_ACT___(GET_ATTRIBUTES, 0x0E)
288 OSD_ACT___(SET_ATTRIBUTES, 0x0F)
289 OSD_ACT___(CREATE_AND_WRITE, 0x12)
290 OSD_ACT___(CREATE_COLLECTION, 0x15)
291 OSD_ACT___(REMOVE_COLLECTION, 0x16)
292 OSD_ACT___(LIST_COLLECTION, 0x17)
293 OSD_ACT___(SET_KEY, 0x18)
294 OSD_ACT___(SET_MASTER_KEY, 0x19)
295 OSD_ACT___(FLUSH_COLLECTION, 0x1A)
296 OSD_ACT___(FLUSH_PARTITION, 0x1B)
297 OSD_ACT___(FLUSH_OSD, 0x1C)
298
299 OSD_ACT_V2(QUERY, 0x20)
300 OSD_ACT_V2(REMOVE_MEMBER_OBJECTS, 0x21)
301 OSD_ACT_V2(GET_MEMBER_ATTRIBUTES, 0x22)
302 OSD_ACT_V2(SET_MEMBER_ATTRIBUTES, 0x23)
303 OSD_ACT_V2(READ_MAP, 0x31)
304
305 OSD_ACT_V1_V2(PERFORM_SCSI_COMMAND, 0x8F7E, 0x8F7C)
306 OSD_ACT_V1_V2(SCSI_TASK_MANAGEMENT, 0x8F7F, 0x8F7D)
307 /* 0x8F80 to 0x8FFF are Vendor specific */
308};
309
310/* osd2r03: 7.1.3.2 List entry format for retrieving attributes */
311struct osd_attributes_list_attrid {
312 __be32 attr_page;
313 __be32 attr_id;
314} __packed;
315
316/*
Boaz Harrosh71f32e32009-04-19 19:11:42 +0300317 * NOTE: v1: is not aligned.
Boaz Harroshde258bf2009-01-25 16:54:10 +0200318 */
Boaz Harrosh71f32e32009-04-19 19:11:42 +0300319struct osdv1_attributes_list_element {
Boaz Harroshde258bf2009-01-25 16:54:10 +0200320 __be32 attr_page;
321 __be32 attr_id;
Boaz Harrosh71f32e32009-04-19 19:11:42 +0300322 __be16 attr_bytes; /* valid bytes at attr_val without padding */
323 u8 attr_val[0];
324} __packed;
325
326/*
327 * osd2r03: 7.1.3.3 List entry format for retrieved attributes and
328 * for setting attributes
329 * NOTE: v2 is 8-bytes aligned
330 */
331struct osdv2_attributes_list_element {
332 __be32 attr_page;
333 __be32 attr_id;
334 __be16 attr_bytes; /* valid bytes at attr_val without padding */
Boaz Harroshde258bf2009-01-25 16:54:10 +0200335 u8 attr_val[0];
336} __packed;
337
338enum {
339 OSDv1_ATTRIBUTES_ELEM_ALIGN = 1,
Boaz Harroshc6572c92009-01-25 17:09:40 +0200340 OSD_ATTRIBUTES_ELEM_ALIGN = 8,
Boaz Harroshde258bf2009-01-25 16:54:10 +0200341};
342
343enum {
344 OSD_ATTR_LIST_ALL_PAGES = 0xFFFFFFFF,
345 OSD_ATTR_LIST_ALL_IN_PAGE = 0xFFFFFFFF,
346};
347
348static inline unsigned osdv1_attr_list_elem_size(unsigned len)
349{
Boaz Harrosh71f32e32009-04-19 19:11:42 +0300350 return ALIGN(len + sizeof(struct osdv1_attributes_list_element),
Boaz Harroshde258bf2009-01-25 16:54:10 +0200351 OSDv1_ATTRIBUTES_ELEM_ALIGN);
352}
353
Boaz Harroshc6572c92009-01-25 17:09:40 +0200354static inline unsigned osdv2_attr_list_elem_size(unsigned len)
355{
Boaz Harrosh71f32e32009-04-19 19:11:42 +0300356 return ALIGN(len + sizeof(struct osdv2_attributes_list_element),
Boaz Harroshc6572c92009-01-25 17:09:40 +0200357 OSD_ATTRIBUTES_ELEM_ALIGN);
358}
359
Boaz Harroshde258bf2009-01-25 16:54:10 +0200360/*
361 * osd2r03: 7.1.3 OSD attributes lists (Table 184) — List type values
362 */
363enum osd_attr_list_types {
364 OSD_ATTR_LIST_GET = 0x1, /* descriptors only */
365 OSD_ATTR_LIST_SET_RETRIEVE = 0x9, /*descriptors/values variable-length*/
366 OSD_V2_ATTR_LIST_MULTIPLE = 0xE, /* ver2, Multiple Objects lists*/
367 OSD_V1_ATTR_LIST_CREATE_MULTIPLE = 0xF,/*ver1, used by create_multple*/
368};
369
370/* osd2r03: 7.1.3.4 Multi-object retrieved attributes format */
371struct osd_attributes_list_multi_header {
372 __be64 object_id;
373 u8 object_type; /* object_type enum below */
374 u8 reserved[5];
375 __be16 list_bytes;
376 /* followed by struct osd_attributes_list_element's */
377};
378
379struct osdv1_attributes_list_header {
380 u8 type; /* low 4-bit only */
381 u8 pad;
382 __be16 list_bytes; /* Initiator shall set to Zero. Only set by target */
383 /*
384 * type=9 followed by struct osd_attributes_list_element's
385 * type=E followed by struct osd_attributes_list_multi_header's
386 */
387} __packed;
388
389static inline unsigned osdv1_list_size(struct osdv1_attributes_list_header *h)
390{
391 return be16_to_cpu(h->list_bytes);
392}
393
Boaz Harroshc6572c92009-01-25 17:09:40 +0200394struct osdv2_attributes_list_header {
395 u8 type; /* lower 4-bits only */
396 u8 pad[3];
397/*4*/ __be32 list_bytes; /* Initiator shall set to zero. Only set by target */
398 /*
399 * type=9 followed by struct osd_attributes_list_element's
400 * type=E followed by struct osd_attributes_list_multi_header's
401 */
402} __packed;
403
404static inline unsigned osdv2_list_size(struct osdv2_attributes_list_header *h)
405{
406 return be32_to_cpu(h->list_bytes);
407}
408
Boaz Harroshde258bf2009-01-25 16:54:10 +0200409/* (osd-r10 6.13)
410 * osd2r03: 6.15 LIST (Table 79) LIST command parameter data.
411 * for root_lstchg below
412 */
413enum {
414 OSD_OBJ_ID_LIST_PAR = 0x1, /* V1-only. Not used in V2 */
415 OSD_OBJ_ID_LIST_LSTCHG = 0x2,
416};
417
418/*
419 * osd2r03: 6.15.2 LIST command parameter data
420 * (Also for LIST COLLECTION)
421 */
422struct osd_obj_id_list {
423 __be64 list_bytes; /* bytes in list excluding list_bytes (-8) */
424 __be64 continuation_id;
425 __be32 list_identifier;
426 u8 pad[3];
427 u8 root_lstchg;
428 __be64 object_ids[0];
429} __packed;
430
431static inline bool osd_is_obj_list_done(struct osd_obj_id_list *list,
432 bool *is_changed)
433{
434 *is_changed = (0 != (list->root_lstchg & OSD_OBJ_ID_LIST_LSTCHG));
435 return 0 != list->continuation_id;
436}
437
438/*
439 * osd2r03: 4.12.4.5 The ALLDATA security method
440 */
441struct osd_data_out_integrity_info {
442 __be64 data_bytes;
443 __be64 set_attributes_bytes;
444 __be64 get_attributes_bytes;
Boaz Harroshf8d3a642009-04-19 19:13:39 +0300445 __u8 integrity_check_value[OSD_CRYPTO_KEYID_SIZE];
Boaz Harroshde258bf2009-01-25 16:54:10 +0200446} __packed;
447
Boaz Harroshf8d3a642009-04-19 19:13:39 +0300448/* Same osd_data_out_integrity_info is used for OSD2/OSD1. The only difference
449 * Is the sizeof the structure since in OSD1 the last array is smaller. Use
450 * below for version independent handling of this structure
451 */
452static inline int osd_data_out_integrity_info_sizeof(bool is_ver1)
453{
454 return sizeof(struct osd_data_out_integrity_info) -
455 (is_ver1 * (OSDv2_CRYPTO_KEYID_SIZE - OSDv1_CRYPTO_KEYID_SIZE));
456}
457
Boaz Harroshde258bf2009-01-25 16:54:10 +0200458struct osd_data_in_integrity_info {
459 __be64 data_bytes;
460 __be64 retrieved_attributes_bytes;
Boaz Harroshf8d3a642009-04-19 19:13:39 +0300461 __u8 integrity_check_value[OSD_CRYPTO_KEYID_SIZE];
Boaz Harroshde258bf2009-01-25 16:54:10 +0200462} __packed;
463
Boaz Harroshf8d3a642009-04-19 19:13:39 +0300464/* Same osd_data_in_integrity_info is used for OSD2/OSD1. The only difference
465 * Is the sizeof the structure since in OSD1 the last array is smaller. Use
466 * below for version independent handling of this structure
467 */
468static inline int osd_data_in_integrity_info_sizeof(bool is_ver1)
469{
470 return sizeof(struct osd_data_in_integrity_info) -
471 (is_ver1 * (OSDv2_CRYPTO_KEYID_SIZE - OSDv1_CRYPTO_KEYID_SIZE));
472}
473
Boaz Harroshde258bf2009-01-25 16:54:10 +0200474struct osd_timestamp {
475 u8 time[6]; /* number of milliseconds since 1/1/1970 UT (big endian) */
476} __packed;
477/* FIXME: define helper functions to convert to/from osd time format */
478
479/*
480 * Capability & Security definitions
481 * osd2r03: 4.11.2.2 Capability format
482 * osd2r03: 5.2.8 Security parameters
483 */
484
485struct osd_key_identifier {
486 u8 id[7]; /* if you know why 7 please email bharrosh@panasas.com */
487} __packed;
488
489/* for osd_capability.format */
490enum {
491 OSD_SEC_CAP_FORMAT_NO_CAPS = 0,
492 OSD_SEC_CAP_FORMAT_VER1 = 1,
493 OSD_SEC_CAP_FORMAT_VER2 = 2,
494};
495
496/* security_method */
497enum {
498 OSD_SEC_NOSEC = 0,
499 OSD_SEC_CAPKEY = 1,
500 OSD_SEC_CMDRSP = 2,
501 OSD_SEC_ALLDATA = 3,
502};
503
504enum object_type {
505 OSD_SEC_OBJ_ROOT = 0x1,
506 OSD_SEC_OBJ_PARTITION = 0x2,
507 OSD_SEC_OBJ_COLLECTION = 0x40,
508 OSD_SEC_OBJ_USER = 0x80,
509};
510
511enum osd_capability_bit_masks {
512 OSD_SEC_CAP_APPEND = BIT(0),
513 OSD_SEC_CAP_OBJ_MGMT = BIT(1),
514 OSD_SEC_CAP_REMOVE = BIT(2),
515 OSD_SEC_CAP_CREATE = BIT(3),
516 OSD_SEC_CAP_SET_ATTR = BIT(4),
517 OSD_SEC_CAP_GET_ATTR = BIT(5),
518 OSD_SEC_CAP_WRITE = BIT(6),
519 OSD_SEC_CAP_READ = BIT(7),
520
521 OSD_SEC_CAP_NONE1 = BIT(8),
522 OSD_SEC_CAP_NONE2 = BIT(9),
523 OSD_SEC_CAP_NONE3 = BIT(10),
524 OSD_SEC_CAP_QUERY = BIT(11), /*v2 only*/
525 OSD_SEC_CAP_M_OBJECT = BIT(12), /*v2 only*/
526 OSD_SEC_CAP_POL_SEC = BIT(13),
527 OSD_SEC_CAP_GLOBAL = BIT(14),
528 OSD_SEC_CAP_DEV_MGMT = BIT(15),
529};
530
531/* for object_descriptor_type (hi nibble used) */
532enum {
533 OSD_SEC_OBJ_DESC_NONE = 0, /* Not allowed */
534 OSD_SEC_OBJ_DESC_OBJ = 1 << 4, /* v1: also collection */
535 OSD_SEC_OBJ_DESC_PAR = 2 << 4, /* also root */
536 OSD_SEC_OBJ_DESC_COL = 3 << 4, /* v2 only */
537};
538
539/* (osd-r10:4.9.2.2)
540 * osd2r03:4.11.2.2 Capability format
541 */
542struct osd_capability_head {
543 u8 format; /* low nibble */
544 u8 integrity_algorithm__key_version; /* MAKE_BYTE(integ_alg, key_ver) */
545 u8 security_method;
546 u8 reserved1;
547/*04*/ struct osd_timestamp expiration_time;
548/*10*/ u8 audit[20];
549/*30*/ u8 discriminator[12];
550/*42*/ struct osd_timestamp object_created_time;
551/*48*/ u8 object_type;
552/*49*/ u8 permissions_bit_mask[5];
553/*54*/ u8 reserved2;
554/*55*/ u8 object_descriptor_type; /* high nibble */
555} __packed;
556
557/*56 v1*/
558struct osdv1_cap_object_descriptor {
559 union {
560 struct {
561/*56*/ __be32 policy_access_tag;
562/*60*/ __be64 allowed_partition_id;
563/*68*/ __be64 allowed_object_id;
564/*76*/ __be32 reserved;
565 } __packed obj_desc;
566
567/*56*/ u8 object_descriptor[24];
568 };
569} __packed;
570/*80 v1*/
571
Boaz Harroshc6572c92009-01-25 17:09:40 +0200572/*56 v2*/
573struct osd_cap_object_descriptor {
574 union {
575 struct {
576/*56*/ __be32 allowed_attributes_access;
577/*60*/ __be32 policy_access_tag;
578/*64*/ __be16 boot_epoch;
579/*66*/ u8 reserved[6];
580/*72*/ __be64 allowed_partition_id;
581/*80*/ __be64 allowed_object_id;
582/*88*/ __be64 allowed_range_length;
583/*96*/ __be64 allowed_range_start;
584 } __packed obj_desc;
585
586/*56*/ u8 object_descriptor[48];
587 };
588} __packed;
589/*104 v2*/
590
591struct osdv1_capability {
Boaz Harroshde258bf2009-01-25 16:54:10 +0200592 struct osd_capability_head h;
593 struct osdv1_cap_object_descriptor od;
594} __packed;
595
Boaz Harroshc6572c92009-01-25 17:09:40 +0200596struct osd_capability {
597 struct osd_capability_head h;
598/* struct osd_cap_object_descriptor od;*/
599 struct osdv1_cap_object_descriptor od; /* FIXME: Pete rev-001 sup */
600} __packed;
601
Boaz Harroshde258bf2009-01-25 16:54:10 +0200602/**
603 * osd_sec_set_caps - set cap-bits into the capabilities header
604 *
605 * @cap: The osd_capability_head to set cap bits to.
606 * @bit_mask: Use an ORed list of enum osd_capability_bit_masks values
607 *
608 * permissions_bit_mask is unaligned use below to set into caps
609 * in a version independent way
610 */
611static inline void osd_sec_set_caps(struct osd_capability_head *cap,
612 u16 bit_mask)
613{
614 /*
615 *Note: The bits above are defined LE order this is because this way
616 * they can grow in the future to more then 16, and still retain
617 * there constant values.
618 */
619 put_unaligned_le16(bit_mask, &cap->permissions_bit_mask);
620}
621
622#endif /* ndef __OSD_PROTOCOL_H__ */