opal_proto.h 9.8 KB

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