opal_proto.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. /*
  2. * Copyright © 2016 Intel Corporation
  3. *
  4. * Authors:
  5. * Rafael Antognolli <rafael.antognolli@intel.com>
  6. * Scott Bauer <scott.bauer@intel.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms and conditions of the GNU General Public License,
  10. * version 2, as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. */
  17. #include <linux/types.h>
  18. #ifndef _OPAL_PROTO_H
  19. #define _OPAL_PROTO_H
  20. /*
  21. * These constant values come from:
  22. * SPC-4 section
  23. * 6.30 SECURITY PROTOCOL IN command / table 265.
  24. */
  25. enum {
  26. TCG_SECP_00 = 0,
  27. TCG_SECP_01,
  28. };
  29. /*
  30. * Token defs derived from:
  31. * TCG_Storage_Architecture_Core_Spec_v2.01_r1.00
  32. * 3.2.2 Data Stream Encoding
  33. */
  34. enum opal_response_token {
  35. OPAL_DTA_TOKENID_BYTESTRING = 0xe0,
  36. OPAL_DTA_TOKENID_SINT = 0xe1,
  37. OPAL_DTA_TOKENID_UINT = 0xe2,
  38. OPAL_DTA_TOKENID_TOKEN = 0xe3, /* actual token is returned */
  39. OPAL_DTA_TOKENID_INVALID = 0X0
  40. };
  41. #define DTAERROR_NO_METHOD_STATUS 0x89
  42. #define GENERIC_HOST_SESSION_NUM 0x41
  43. #define TPER_SYNC_SUPPORTED 0x01
  44. #define MBR_ENABLED_MASK 0x10
  45. #define TINY_ATOM_DATA_MASK 0x3F
  46. #define TINY_ATOM_SIGNED 0x40
  47. #define SHORT_ATOM_ID 0x80
  48. #define SHORT_ATOM_BYTESTRING 0x20
  49. #define SHORT_ATOM_SIGNED 0x10
  50. #define SHORT_ATOM_LEN_MASK 0xF
  51. #define MEDIUM_ATOM_ID 0xC0
  52. #define MEDIUM_ATOM_BYTESTRING 0x10
  53. #define MEDIUM_ATOM_SIGNED 0x8
  54. #define MEDIUM_ATOM_LEN_MASK 0x7
  55. #define LONG_ATOM_ID 0xe0
  56. #define LONG_ATOM_BYTESTRING 0x2
  57. #define LONG_ATOM_SIGNED 0x1
  58. /* Derived from TCG Core spec 2.01 Section:
  59. * 3.2.2.1
  60. * Data Type
  61. */
  62. #define TINY_ATOM_BYTE 0x7F
  63. #define SHORT_ATOM_BYTE 0xBF
  64. #define MEDIUM_ATOM_BYTE 0xDF
  65. #define LONG_ATOM_BYTE 0xE3
  66. #define OPAL_INVAL_PARAM 12
  67. #define OPAL_MANUFACTURED_INACTIVE 0x08
  68. #define OPAL_DISCOVERY_COMID 0x0001
  69. #define LOCKING_RANGE_NON_GLOBAL 0x03
  70. /*
  71. * User IDs used in the TCG storage SSCs
  72. * Derived from: TCG_Storage_Architecture_Core_Spec_v2.01_r1.00
  73. * Section: 6.3 Assigned UIDs
  74. */
  75. #define OPAL_UID_LENGTH 8
  76. #define OPAL_METHOD_LENGTH 8
  77. #define OPAL_MSID_KEYLEN 15
  78. #define OPAL_UID_LENGTH_HALF 4
  79. /* Enum to index OPALUID array */
  80. enum opal_uid {
  81. /* users */
  82. OPAL_SMUID_UID,
  83. OPAL_THISSP_UID,
  84. OPAL_ADMINSP_UID,
  85. OPAL_LOCKINGSP_UID,
  86. OPAL_ENTERPRISE_LOCKINGSP_UID,
  87. OPAL_ANYBODY_UID,
  88. OPAL_SID_UID,
  89. OPAL_ADMIN1_UID,
  90. OPAL_USER1_UID,
  91. OPAL_USER2_UID,
  92. OPAL_PSID_UID,
  93. OPAL_ENTERPRISE_BANDMASTER0_UID,
  94. OPAL_ENTERPRISE_ERASEMASTER_UID,
  95. /* tables */
  96. OPAL_LOCKINGRANGE_GLOBAL,
  97. OPAL_LOCKINGRANGE_ACE_RDLOCKED,
  98. OPAL_LOCKINGRANGE_ACE_WRLOCKED,
  99. OPAL_MBRCONTROL,
  100. OPAL_MBR,
  101. OPAL_AUTHORITY_TABLE,
  102. OPAL_C_PIN_TABLE,
  103. OPAL_LOCKING_INFO_TABLE,
  104. OPAL_ENTERPRISE_LOCKING_INFO_TABLE,
  105. /* C_PIN_TABLE object ID's */
  106. OPAL_C_PIN_MSID,
  107. OPAL_C_PIN_SID,
  108. OPAL_C_PIN_ADMIN1,
  109. /* half UID's (only first 4 bytes used) */
  110. OPAL_HALF_UID_AUTHORITY_OBJ_REF,
  111. OPAL_HALF_UID_BOOLEAN_ACE,
  112. /* omitted optional parameter */
  113. OPAL_UID_HEXFF,
  114. };
  115. #define OPAL_METHOD_LENGTH 8
  116. /* Enum for indexing the OPALMETHOD array */
  117. enum opal_method {
  118. OPAL_PROPERTIES,
  119. OPAL_STARTSESSION,
  120. OPAL_REVERT,
  121. OPAL_ACTIVATE,
  122. OPAL_EGET,
  123. OPAL_ESET,
  124. OPAL_NEXT,
  125. OPAL_EAUTHENTICATE,
  126. OPAL_GETACL,
  127. OPAL_GENKEY,
  128. OPAL_REVERTSP,
  129. OPAL_GET,
  130. OPAL_SET,
  131. OPAL_AUTHENTICATE,
  132. OPAL_RANDOM,
  133. OPAL_ERASE,
  134. };
  135. enum opal_token {
  136. /* Boolean */
  137. OPAL_TRUE = 0x01,
  138. OPAL_FALSE = 0x00,
  139. OPAL_BOOLEAN_EXPR = 0x03,
  140. /* cellblocks */
  141. OPAL_TABLE = 0x00,
  142. OPAL_STARTROW = 0x01,
  143. OPAL_ENDROW = 0x02,
  144. OPAL_STARTCOLUMN = 0x03,
  145. OPAL_ENDCOLUMN = 0x04,
  146. OPAL_VALUES = 0x01,
  147. /* authority table */
  148. OPAL_PIN = 0x03,
  149. /* locking tokens */
  150. OPAL_RANGESTART = 0x03,
  151. OPAL_RANGELENGTH = 0x04,
  152. OPAL_READLOCKENABLED = 0x05,
  153. OPAL_WRITELOCKENABLED = 0x06,
  154. OPAL_READLOCKED = 0x07,
  155. OPAL_WRITELOCKED = 0x08,
  156. OPAL_ACTIVEKEY = 0x0A,
  157. /* locking info table */
  158. OPAL_MAXRANGES = 0x04,
  159. /* mbr control */
  160. OPAL_MBRENABLE = 0x01,
  161. OPAL_MBRDONE = 0x02,
  162. /* properties */
  163. OPAL_HOSTPROPERTIES = 0x00,
  164. /* atoms */
  165. OPAL_STARTLIST = 0xf0,
  166. OPAL_ENDLIST = 0xf1,
  167. OPAL_STARTNAME = 0xf2,
  168. OPAL_ENDNAME = 0xf3,
  169. OPAL_CALL = 0xf8,
  170. OPAL_ENDOFDATA = 0xf9,
  171. OPAL_ENDOFSESSION = 0xfa,
  172. OPAL_STARTTRANSACTON = 0xfb,
  173. OPAL_ENDTRANSACTON = 0xfC,
  174. OPAL_EMPTYATOM = 0xff,
  175. OPAL_WHERE = 0x00,
  176. };
  177. /* Locking state for a locking range */
  178. enum opal_lockingstate {
  179. OPAL_LOCKING_READWRITE = 0x01,
  180. OPAL_LOCKING_READONLY = 0x02,
  181. OPAL_LOCKING_LOCKED = 0x03,
  182. };
  183. /* Packets derived from:
  184. * TCG_Storage_Architecture_Core_Spec_v2.01_r1.00
  185. * Secion: 3.2.3 ComPackets, Packets & Subpackets
  186. */
  187. /* Comm Packet (header) for transmissions. */
  188. struct opal_compacket {
  189. __be32 reserved0;
  190. u8 extendedComID[4];
  191. __be32 outstandingData;
  192. __be32 minTransfer;
  193. __be32 length;
  194. };
  195. /* Packet structure. */
  196. struct opal_packet {
  197. __be32 tsn;
  198. __be32 hsn;
  199. __be32 seq_number;
  200. __be16 reserved0;
  201. __be16 ack_type;
  202. __be32 acknowledgment;
  203. __be32 length;
  204. };
  205. /* Data sub packet header */
  206. struct opal_data_subpacket {
  207. u8 reserved0[6];
  208. __be16 kind;
  209. __be32 length;
  210. };
  211. /* header of a response */
  212. struct opal_header {
  213. struct opal_compacket cp;
  214. struct opal_packet pkt;
  215. struct opal_data_subpacket subpkt;
  216. };
  217. #define FC_TPER 0x0001
  218. #define FC_LOCKING 0x0002
  219. #define FC_GEOMETRY 0x0003
  220. #define FC_ENTERPRISE 0x0100
  221. #define FC_DATASTORE 0x0202
  222. #define FC_SINGLEUSER 0x0201
  223. #define FC_OPALV100 0x0200
  224. #define FC_OPALV200 0x0203
  225. /*
  226. * The Discovery 0 Header. As defined in
  227. * Opal SSC Documentation
  228. * Section: 3.3.5 Capability Discovery
  229. */
  230. struct d0_header {
  231. __be32 length; /* the length of the header 48 in 2.00.100 */
  232. __be32 revision; /**< revision of the header 1 in 2.00.100 */
  233. __be32 reserved01;
  234. __be32 reserved02;
  235. /*
  236. * the remainder of the structure is vendor specific and will not be
  237. * addressed now
  238. */
  239. u8 ignored[32];
  240. };
  241. /*
  242. * TPer Feature Descriptor. Contains flags indicating support for the
  243. * TPer features described in the OPAL specification. The names match the
  244. * OPAL terminology
  245. *
  246. * code == 0x001 in 2.00.100
  247. */
  248. struct d0_tper_features {
  249. /*
  250. * supported_features bits:
  251. * bit 7: reserved
  252. * bit 6: com ID management
  253. * bit 5: reserved
  254. * bit 4: streaming support
  255. * bit 3: buffer management
  256. * bit 2: ACK/NACK
  257. * bit 1: async
  258. * bit 0: sync
  259. */
  260. u8 supported_features;
  261. /*
  262. * bytes 5 through 15 are reserved, but we represent the first 3 as
  263. * u8 to keep the other two 32bits integers aligned.
  264. */
  265. u8 reserved01[3];
  266. __be32 reserved02;
  267. __be32 reserved03;
  268. };
  269. /*
  270. * Locking Feature Descriptor. Contains flags indicating support for the
  271. * locking features described in the OPAL specification. The names match the
  272. * OPAL terminology
  273. *
  274. * code == 0x0002 in 2.00.100
  275. */
  276. struct d0_locking_features {
  277. /*
  278. * supported_features bits:
  279. * bits 6-7: reserved
  280. * bit 5: MBR done
  281. * bit 4: MBR enabled
  282. * bit 3: media encryption
  283. * bit 2: locked
  284. * bit 1: locking enabled
  285. * bit 0: locking supported
  286. */
  287. u8 supported_features;
  288. /*
  289. * bytes 5 through 15 are reserved, but we represent the first 3 as
  290. * u8 to keep the other two 32bits integers aligned.
  291. */
  292. u8 reserved01[3];
  293. __be32 reserved02;
  294. __be32 reserved03;
  295. };
  296. /*
  297. * Geometry Feature Descriptor. Contains flags indicating support for the
  298. * geometry features described in the OPAL specification. The names match the
  299. * OPAL terminology
  300. *
  301. * code == 0x0003 in 2.00.100
  302. */
  303. struct d0_geometry_features {
  304. /*
  305. * skip 32 bits from header, needed to align the struct to 64 bits.
  306. */
  307. u8 header[4];
  308. /*
  309. * reserved01:
  310. * bits 1-6: reserved
  311. * bit 0: align
  312. */
  313. u8 reserved01;
  314. u8 reserved02[7];
  315. __be32 logical_block_size;
  316. __be64 alignment_granularity;
  317. __be64 lowest_aligned_lba;
  318. };
  319. /*
  320. * Enterprise SSC Feature
  321. *
  322. * code == 0x0100
  323. */
  324. struct d0_enterprise_ssc {
  325. __be16 baseComID;
  326. __be16 numComIDs;
  327. /* range_crossing:
  328. * bits 1-6: reserved
  329. * bit 0: range crossing
  330. */
  331. u8 range_crossing;
  332. u8 reserved01;
  333. __be16 reserved02;
  334. __be32 reserved03;
  335. __be32 reserved04;
  336. };
  337. /*
  338. * Opal V1 feature
  339. *
  340. * code == 0x0200
  341. */
  342. struct d0_opal_v100 {
  343. __be16 baseComID;
  344. __be16 numComIDs;
  345. };
  346. /*
  347. * Single User Mode feature
  348. *
  349. * code == 0x0201
  350. */
  351. struct d0_single_user_mode {
  352. __be32 num_locking_objects;
  353. /* reserved01:
  354. * bit 0: any
  355. * bit 1: all
  356. * bit 2: policy
  357. * bits 3-7: reserved
  358. */
  359. u8 reserved01;
  360. u8 reserved02;
  361. __be16 reserved03;
  362. __be32 reserved04;
  363. };
  364. /*
  365. * Additonal Datastores feature
  366. *
  367. * code == 0x0202
  368. */
  369. struct d0_datastore_table {
  370. __be16 reserved01;
  371. __be16 max_tables;
  372. __be32 max_size_tables;
  373. __be32 table_size_alignment;
  374. };
  375. /*
  376. * OPAL 2.0 feature
  377. *
  378. * code == 0x0203
  379. */
  380. struct d0_opal_v200 {
  381. __be16 baseComID;
  382. __be16 numComIDs;
  383. /* range_crossing:
  384. * bits 1-6: reserved
  385. * bit 0: range crossing
  386. */
  387. u8 range_crossing;
  388. /* num_locking_admin_auth:
  389. * not aligned to 16 bits, so use two u8.
  390. * stored in big endian:
  391. * 0: MSB
  392. * 1: LSB
  393. */
  394. u8 num_locking_admin_auth[2];
  395. /* num_locking_user_auth:
  396. * not aligned to 16 bits, so use two u8.
  397. * stored in big endian:
  398. * 0: MSB
  399. * 1: LSB
  400. */
  401. u8 num_locking_user_auth[2];
  402. u8 initialPIN;
  403. u8 revertedPIN;
  404. u8 reserved01;
  405. __be32 reserved02;
  406. };
  407. /* Union of features used to parse the discovery 0 response */
  408. struct d0_features {
  409. __be16 code;
  410. /*
  411. * r_version bits:
  412. * bits 4-7: version
  413. * bits 0-3: reserved
  414. */
  415. u8 r_version;
  416. u8 length;
  417. u8 features[];
  418. };
  419. #endif /* _OPAL_PROTO_H */