blob: 62b2ab8c69d45318ba93419184b608348928d5e2 [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,
Boaz Harroshe9da4d72009-04-19 19:17:54 +030027
Boaz Harroshde258bf2009-01-25 16:54:10 +020028 /* Latest supported version */
Boaz Harroshe9da4d72009-04-19 19:17:54 +030029 OSDv2_ADDITIONAL_CDB_LENGTH = 228,
Boaz Harroshc6572c92009-01-25 17:09:40 +020030 OSD_ADDITIONAL_CDB_LENGTH =
Boaz Harroshe9da4d72009-04-19 19:17:54 +030031 OSDv2_ADDITIONAL_CDB_LENGTH,
Boaz Harroshc6572c92009-01-25 17:09:40 +020032 OSD_TOTAL_CDB_LEN = OSD_ADDITIONAL_CDB_LENGTH + 8,
Boaz Harroshe9da4d72009-04-19 19:17:54 +030033 OSD_CAP_LEN = 104,
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 Harroshe9da4d72009-04-19 19:17:54 +030037 OSDv2_CRYPTO_KEYID_SIZE = 32,
Boaz Harroshf8d3a642009-04-19 19:13:39 +030038 OSD_CRYPTO_KEYID_SIZE = OSDv2_CRYPTO_KEYID_SIZE,
Boaz Harroshde258bf2009-01-25 16:54:10 +020039 OSD_CRYPTO_SEED_SIZE = 4,
40 OSD_CRYPTO_NONCE_SIZE = 12,
41 OSD_MAX_SENSE_LEN = 252, /* from SPC-3 */
42
43 OSD_PARTITION_FIRST_ID = 0x10000,
44 OSD_OBJECT_FIRST_ID = 0x10000,
45};
46
47/* (osd-r10 5.2.4)
48 * osd2r03: 5.2.3 Caching control bits
49 */
50enum osd_options_byte {
51 OSD_CDB_FUA = 0x08, /* Force Unit Access */
52 OSD_CDB_DPO = 0x10, /* Disable Page Out */
53};
54
55/*
56 * osd2r03: 5.2.5 Isolation.
57 * First 3 bits, V2-only.
58 * Also for attr 110h "default isolation method" at Root Information page
59 */
60enum 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,
67};
68
69/* (osd-r10: 6.7)
70 * osd2r03: 6.8 FLUSH, FLUSH COLLECTION, FLUSH OSD, FLUSH PARTITION
71 */
72enum osd_options_flush_scope_values {
73 OSD_CDB_FLUSH_ALL = 0,
74 OSD_CDB_FLUSH_ATTR_ONLY = 1,
75
76 OSD_CDB_FLUSH_ALL_RECURSIVE = 2,
77 /* V2-only */
78 OSD_CDB_FLUSH_ALL_RANGE = 2,
79};
80
81/* osd2r03: 5.2.10 Timestamps control */
82enum {
83 OSD_CDB_NORMAL_TIMESTAMPS = 0,
84 OSD_CDB_BYPASS_TIMESTAMPS = 0x7f,
85};
86
87/* (osd-r10: 5.2.2.1)
88 * osd2r03: 5.2.4.1 Get and set attributes CDB format selection
89 * 2 bits at second nibble of command_specific_options byte
90 */
91enum osd_attributes_mode {
92 /* V2-only */
93 OSD_CDB_SET_ONE_ATTR = 0x10,
94
95 OSD_CDB_GET_ATTR_PAGE_SET_ONE = 0x20,
96 OSD_CDB_GET_SET_ATTR_LISTS = 0x30,
97
98 OSD_CDB_GET_SET_ATTR_MASK = 0x30,
99};
100
101/* (osd-r10: 4.12.5)
102 * osd2r03: 4.14.5 Data-In and Data-Out buffer offsets
103 * byte offset = mantissa * (2^(exponent+8))
104 * struct {
105 * unsigned mantissa: 28;
106 * int exponent: 04;
107 * }
108 */
109typedef __be32 __bitwise osd_cdb_offset;
110
111enum {
112 OSD_OFFSET_UNUSED = 0xFFFFFFFF,
113 OSD_OFFSET_MAX_BITS = 28,
114
115 OSDv1_OFFSET_MIN_SHIFT = 8,
Boaz Harroshc6572c92009-01-25 17:09:40 +0200116 OSD_OFFSET_MIN_SHIFT = 3,
Boaz Harroshde258bf2009-01-25 16:54:10 +0200117 OSD_OFFSET_MAX_SHIFT = 16,
118};
119
120/* Return the smallest allowed encoded offset that contains @offset.
121 *
122 * The actual encoded offset returned is @offset + *padding.
123 * (up to max_shift, non-inclusive)
124 */
125osd_cdb_offset __osd_encode_offset(u64 offset, unsigned *padding,
126 int min_shift, int max_shift);
127
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.
131 */
132static inline osd_cdb_offset osd_encode_offset_v1(u64 offset, unsigned *padding)
133{
134 return __osd_encode_offset(offset, padding,
135 OSDv1_OFFSET_MIN_SHIFT, OSD_OFFSET_MAX_SHIFT);
136}
137
Boaz Harroshc6572c92009-01-25 17:09:40 +0200138/* 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)
141 */
142static inline osd_cdb_offset osd_encode_offset_v2(u64 offset, unsigned *padding)
143{
144 return __osd_encode_offset(offset, padding,
145 OSD_OFFSET_MIN_SHIFT, OSD_OFFSET_MAX_SHIFT);
146}
147
Boaz Harroshde258bf2009-01-25 16:54:10 +0200148/* osd2r03: 5.2.1 Overview */
149struct osd_cdb_head {
150 struct scsi_varlen_cdb_hdr varlen_cdb;
151/*10*/ u8 options;
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;
162 } __packed v1;
Boaz Harroshc6572c92009-01-25 17:09:40 +0200163
164 struct __osdv2_cdb_addr_len {
165 /* called allocation_length in some commands */
166/*32*/ __be64 length;
167/*40*/ __be64 start_address;
Boaz Harroshe9da4d72009-04-19 19:17:54 +0300168 union {
169/*48*/ __be32 list_identifier;/* Rarely used */
170 /* OSD2r05 5.2.5 CDB continuation length */
171/*48*/ __be32 cdb_continuation_length;
172 };
Boaz Harroshc6572c92009-01-25 17:09:40 +0200173 } __packed v2;
Boaz Harroshde258bf2009-01-25 16:54:10 +0200174 };
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;
180
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;
186
187 struct osd_attributes_list_mode {
188/*52*/ __be32 get_attr_desc_bytes;
189/*56*/ osd_cdb_offset get_attr_desc_offset;
190
191/*60*/ __be32 get_attr_alloc_length;
192/*64*/ osd_cdb_offset get_attr_offset;
193
194/*68*/ __be32 set_attr_bytes;
195/*72*/ osd_cdb_offset set_attr_offset;
196 __be32 not_used;
197/*80*/ } __packed attrs_list;
198
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];
207 };
208} __packed;
209/*80*/
210
211/*160 v1*/
Boaz Harroshf8d3a642009-04-19 19:13:39 +0300212struct osdv1_security_parameters {
213/*160*/u8 integrity_check_value[OSDv1_CRYPTO_KEYID_SIZE];
Boaz Harroshde258bf2009-01-25 16:54:10 +0200214/*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;
217} __packed;
218/*200 v1*/
Boaz Harroshc6572c92009-01-25 17:09:40 +0200219
Boaz Harroshf8d3a642009-04-19 19:13:39 +0300220/*184 v2*/
221struct 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;
226} __packed;
227/*236 v2*/
228
229struct osd_security_parameters {
230 union {
231 struct osdv1_security_parameters v1;
232 struct osdv2_security_parameters v2;
233 };
234};
Boaz Harroshde258bf2009-01-25 16:54:10 +0200235
236struct osdv1_cdb {
237 struct osd_cdb_head h;
238 u8 caps[OSDv1_CAP_LEN];
Boaz Harroshf8d3a642009-04-19 19:13:39 +0300239 struct osdv1_security_parameters sec_params;
Boaz Harroshde258bf2009-01-25 16:54:10 +0200240} __packed;
241
Boaz Harroshc6572c92009-01-25 17:09:40 +0200242struct osdv2_cdb {
243 struct osd_cdb_head h;
244 u8 caps[OSD_CAP_LEN];
Boaz Harroshf8d3a642009-04-19 19:13:39 +0300245 struct osdv2_security_parameters sec_params;
Boaz Harroshc6572c92009-01-25 17:09:40 +0200246} __packed;
247
Boaz Harroshde258bf2009-01-25 16:54:10 +0200248struct osd_cdb {
249 union {
250 struct osdv1_cdb v1;
Boaz Harroshc6572c92009-01-25 17:09:40 +0200251 struct osdv2_cdb v2;
Boaz Harroshde258bf2009-01-25 16:54:10 +0200252 u8 buff[OSD_TOTAL_CDB_LEN];
253 };
254} __packed;
255
256static inline struct osd_cdb_head *osd_cdb_head(struct osd_cdb *ocdb)
257{
258 return (struct osd_cdb_head *)ocdb->buff;
259}
260
261/* define both version actions
262 * Ex name = FORMAT_OSD we have OSD_ACT_FORMAT_OSD && OSDv1_ACT_FORMAT_OSD
263 */
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),
267
268/* V2 only actions */
269#define OSD_ACT_V2(Name, Num) \
270 OSD_ACT_##Name = __constant_cpu_to_be16(0x8880 + Num),
271
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),
275
276enum 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)
301
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)
307
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 */
311};
312
313/* osd2r03: 7.1.3.2 List entry format for retrieving attributes */
314struct osd_attributes_list_attrid {
315 __be32 attr_page;
316 __be32 attr_id;
317} __packed;
318
319/*
Boaz Harrosh71f32e32009-04-19 19:11:42 +0300320 * NOTE: v1: is not aligned.
Boaz Harroshde258bf2009-01-25 16:54:10 +0200321 */
Boaz Harrosh71f32e32009-04-19 19:11:42 +0300322struct osdv1_attributes_list_element {
Boaz Harroshde258bf2009-01-25 16:54:10 +0200323 __be32 attr_page;
324 __be32 attr_id;
Boaz Harrosh71f32e32009-04-19 19:11:42 +0300325 __be16 attr_bytes; /* valid bytes at attr_val without padding */
326 u8 attr_val[0];
327} __packed;
328
329/*
330 * osd2r03: 7.1.3.3 List entry format for retrieved attributes and
331 * for setting attributes
332 * NOTE: v2 is 8-bytes aligned
333 */
334struct osdv2_attributes_list_element {
335 __be32 attr_page;
336 __be32 attr_id;
Boaz Harroshe9da4d72009-04-19 19:17:54 +0300337 u8 reserved[6];
Boaz Harrosh71f32e32009-04-19 19:11:42 +0300338 __be16 attr_bytes; /* valid bytes at attr_val without padding */
Boaz Harroshde258bf2009-01-25 16:54:10 +0200339 u8 attr_val[0];
340} __packed;
341
342enum {
343 OSDv1_ATTRIBUTES_ELEM_ALIGN = 1,
Boaz Harroshc6572c92009-01-25 17:09:40 +0200344 OSD_ATTRIBUTES_ELEM_ALIGN = 8,
Boaz Harroshde258bf2009-01-25 16:54:10 +0200345};
346
347enum {
348 OSD_ATTR_LIST_ALL_PAGES = 0xFFFFFFFF,
349 OSD_ATTR_LIST_ALL_IN_PAGE = 0xFFFFFFFF,
350};
351
352static inline unsigned osdv1_attr_list_elem_size(unsigned len)
353{
Boaz Harrosh71f32e32009-04-19 19:11:42 +0300354 return ALIGN(len + sizeof(struct osdv1_attributes_list_element),
Boaz Harroshde258bf2009-01-25 16:54:10 +0200355 OSDv1_ATTRIBUTES_ELEM_ALIGN);
356}
357
Boaz Harroshc6572c92009-01-25 17:09:40 +0200358static inline unsigned osdv2_attr_list_elem_size(unsigned len)
359{
Boaz Harrosh71f32e32009-04-19 19:11:42 +0300360 return ALIGN(len + sizeof(struct osdv2_attributes_list_element),
Boaz Harroshc6572c92009-01-25 17:09:40 +0200361 OSD_ATTRIBUTES_ELEM_ALIGN);
362}
363
Boaz Harroshde258bf2009-01-25 16:54:10 +0200364/*
365 * osd2r03: 7.1.3 OSD attributes lists (Table 184) — List type values
366 */
367enum 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*/
372};
373
374/* osd2r03: 7.1.3.4 Multi-object retrieved attributes format */
375struct osd_attributes_list_multi_header {
376 __be64 object_id;
377 u8 object_type; /* object_type enum below */
378 u8 reserved[5];
379 __be16 list_bytes;
380 /* followed by struct osd_attributes_list_element's */
381};
382
383struct osdv1_attributes_list_header {
384 u8 type; /* low 4-bit only */
385 u8 pad;
386 __be16 list_bytes; /* Initiator shall set to Zero. Only set by target */
387 /*
388 * type=9 followed by struct osd_attributes_list_element's
389 * type=E followed by struct osd_attributes_list_multi_header's
390 */
391} __packed;
392
393static inline unsigned osdv1_list_size(struct osdv1_attributes_list_header *h)
394{
395 return be16_to_cpu(h->list_bytes);
396}
397
Boaz Harroshc6572c92009-01-25 17:09:40 +0200398struct osdv2_attributes_list_header {
399 u8 type; /* lower 4-bits only */
400 u8 pad[3];
401/*4*/ __be32 list_bytes; /* Initiator shall set to zero. Only set by target */
402 /*
403 * type=9 followed by struct osd_attributes_list_element's
404 * type=E followed by struct osd_attributes_list_multi_header's
405 */
406} __packed;
407
408static inline unsigned osdv2_list_size(struct osdv2_attributes_list_header *h)
409{
410 return be32_to_cpu(h->list_bytes);
411}
412
Boaz Harroshde258bf2009-01-25 16:54:10 +0200413/* (osd-r10 6.13)
414 * osd2r03: 6.15 LIST (Table 79) LIST command parameter data.
415 * for root_lstchg below
416 */
417enum {
418 OSD_OBJ_ID_LIST_PAR = 0x1, /* V1-only. Not used in V2 */
419 OSD_OBJ_ID_LIST_LSTCHG = 0x2,
420};
421
422/*
423 * osd2r03: 6.15.2 LIST command parameter data
424 * (Also for LIST COLLECTION)
425 */
426struct osd_obj_id_list {
427 __be64 list_bytes; /* bytes in list excluding list_bytes (-8) */
428 __be64 continuation_id;
429 __be32 list_identifier;
430 u8 pad[3];
431 u8 root_lstchg;
432 __be64 object_ids[0];
433} __packed;
434
435static inline bool osd_is_obj_list_done(struct osd_obj_id_list *list,
436 bool *is_changed)
437{
438 *is_changed = (0 != (list->root_lstchg & OSD_OBJ_ID_LIST_LSTCHG));
439 return 0 != list->continuation_id;
440}
441
442/*
443 * osd2r03: 4.12.4.5 The ALLDATA security method
444 */
445struct osd_data_out_integrity_info {
446 __be64 data_bytes;
447 __be64 set_attributes_bytes;
448 __be64 get_attributes_bytes;
Boaz Harroshf8d3a642009-04-19 19:13:39 +0300449 __u8 integrity_check_value[OSD_CRYPTO_KEYID_SIZE];
Boaz Harroshde258bf2009-01-25 16:54:10 +0200450} __packed;
451
Boaz Harroshf8d3a642009-04-19 19:13:39 +0300452/* 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
455 */
456static inline int osd_data_out_integrity_info_sizeof(bool is_ver1)
457{
458 return sizeof(struct osd_data_out_integrity_info) -
459 (is_ver1 * (OSDv2_CRYPTO_KEYID_SIZE - OSDv1_CRYPTO_KEYID_SIZE));
460}
461
Boaz Harroshde258bf2009-01-25 16:54:10 +0200462struct osd_data_in_integrity_info {
463 __be64 data_bytes;
464 __be64 retrieved_attributes_bytes;
Boaz Harroshf8d3a642009-04-19 19:13:39 +0300465 __u8 integrity_check_value[OSD_CRYPTO_KEYID_SIZE];
Boaz Harroshde258bf2009-01-25 16:54:10 +0200466} __packed;
467
Boaz Harroshf8d3a642009-04-19 19:13:39 +0300468/* 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
471 */
472static inline int osd_data_in_integrity_info_sizeof(bool is_ver1)
473{
474 return sizeof(struct osd_data_in_integrity_info) -
475 (is_ver1 * (OSDv2_CRYPTO_KEYID_SIZE - OSDv1_CRYPTO_KEYID_SIZE));
476}
477
Boaz Harroshde258bf2009-01-25 16:54:10 +0200478struct osd_timestamp {
479 u8 time[6]; /* number of milliseconds since 1/1/1970 UT (big endian) */
480} __packed;
481/* FIXME: define helper functions to convert to/from osd time format */
482
483/*
484 * Capability & Security definitions
485 * osd2r03: 4.11.2.2 Capability format
486 * osd2r03: 5.2.8 Security parameters
487 */
488
489struct osd_key_identifier {
490 u8 id[7]; /* if you know why 7 please email bharrosh@panasas.com */
491} __packed;
492
493/* for osd_capability.format */
494enum {
495 OSD_SEC_CAP_FORMAT_NO_CAPS = 0,
496 OSD_SEC_CAP_FORMAT_VER1 = 1,
497 OSD_SEC_CAP_FORMAT_VER2 = 2,
498};
499
500/* security_method */
501enum {
502 OSD_SEC_NOSEC = 0,
503 OSD_SEC_CAPKEY = 1,
504 OSD_SEC_CMDRSP = 2,
505 OSD_SEC_ALLDATA = 3,
506};
507
508enum object_type {
509 OSD_SEC_OBJ_ROOT = 0x1,
510 OSD_SEC_OBJ_PARTITION = 0x2,
511 OSD_SEC_OBJ_COLLECTION = 0x40,
512 OSD_SEC_OBJ_USER = 0x80,
513};
514
515enum 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),
524
525 OSD_SEC_CAP_NONE1 = BIT(8),
526 OSD_SEC_CAP_NONE2 = BIT(9),
Boaz Harroshe9da4d72009-04-19 19:17:54 +0300527 OSD_SEC_GBL_REM = BIT(10), /*v2 only*/
Boaz Harroshde258bf2009-01-25 16:54:10 +0200528 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),
533};
534
535/* for object_descriptor_type (hi nibble used) */
536enum {
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 */
541};
542
543/* (osd-r10:4.9.2.2)
544 * osd2r03:4.11.2.2 Capability format
545 */
546struct osd_capability_head {
547 u8 format; /* low nibble */
548 u8 integrity_algorithm__key_version; /* MAKE_BYTE(integ_alg, key_ver) */
549 u8 security_method;
550 u8 reserved1;
551/*04*/ struct osd_timestamp expiration_time;
552/*10*/ u8 audit[20];
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];
557/*54*/ u8 reserved2;
558/*55*/ u8 object_descriptor_type; /* high nibble */
559} __packed;
560
561/*56 v1*/
562struct osdv1_cap_object_descriptor {
563 union {
564 struct {
565/*56*/ __be32 policy_access_tag;
566/*60*/ __be64 allowed_partition_id;
567/*68*/ __be64 allowed_object_id;
568/*76*/ __be32 reserved;
569 } __packed obj_desc;
570
571/*56*/ u8 object_descriptor[24];
572 };
573} __packed;
574/*80 v1*/
575
Boaz Harroshc6572c92009-01-25 17:09:40 +0200576/*56 v2*/
577struct osd_cap_object_descriptor {
578 union {
579 struct {
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;
588 } __packed obj_desc;
589
590/*56*/ u8 object_descriptor[48];
591 };
592} __packed;
593/*104 v2*/
594
595struct osdv1_capability {
Boaz Harroshde258bf2009-01-25 16:54:10 +0200596 struct osd_capability_head h;
597 struct osdv1_cap_object_descriptor od;
598} __packed;
599
Boaz Harroshc6572c92009-01-25 17:09:40 +0200600struct osd_capability {
601 struct osd_capability_head h;
Boaz Harroshe9da4d72009-04-19 19:17:54 +0300602 struct osd_cap_object_descriptor od;
Boaz Harroshc6572c92009-01-25 17:09:40 +0200603} __packed;
604
Boaz Harroshde258bf2009-01-25 16:54:10 +0200605/**
606 * osd_sec_set_caps - set cap-bits into the capabilities header
607 *
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
610 *
611 * permissions_bit_mask is unaligned use below to set into caps
612 * in a version independent way
613 */
614static inline void osd_sec_set_caps(struct osd_capability_head *cap,
615 u16 bit_mask)
616{
617 /*
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.
621 */
622 put_unaligned_le16(bit_mask, &cap->permissions_bit_mask);
623}
624
625#endif /* ndef __OSD_PROTOCOL_H__ */