osd_protocol.h 13 KB

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