opal_proto.h 9.4 KB

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