opal_proto.h 9.5 KB

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