osd_protocol.h 18 KB

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