osd_protocol.h 17 KB

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