xref: /linux/include/uapi/linux/sed-opal.h (revision a1c613ae4c322ddd58d5a8539dbfba2a0380a8c0)
1e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
219641f2dSScott Bauer /*
319641f2dSScott Bauer  * Copyright © 2016 Intel Corporation
419641f2dSScott Bauer  *
519641f2dSScott Bauer  * Authors:
619641f2dSScott Bauer  *    Rafael Antognolli <rafael.antognolli@intel.com>
719641f2dSScott Bauer  *    Scott  Bauer      <scott.bauer@intel.com>
819641f2dSScott Bauer  */
919641f2dSScott Bauer 
1019641f2dSScott Bauer #ifndef _UAPI_SED_OPAL_H
1119641f2dSScott Bauer #define _UAPI_SED_OPAL_H
1219641f2dSScott Bauer 
1319641f2dSScott Bauer #include <linux/types.h>
1419641f2dSScott Bauer 
1519641f2dSScott Bauer #define OPAL_KEY_MAX 256
1619641f2dSScott Bauer #define OPAL_MAX_LRS 9
1719641f2dSScott Bauer 
1819641f2dSScott Bauer enum opal_mbr {
1919641f2dSScott Bauer 	OPAL_MBR_ENABLE = 0x0,
2019641f2dSScott Bauer 	OPAL_MBR_DISABLE = 0x01,
2119641f2dSScott Bauer };
2219641f2dSScott Bauer 
23c9888443SJonas Rabenstein enum opal_mbr_done_flag {
24c9888443SJonas Rabenstein 	OPAL_MBR_NOT_DONE = 0x0,
25c9888443SJonas Rabenstein 	OPAL_MBR_DONE = 0x01
26c9888443SJonas Rabenstein };
27c9888443SJonas Rabenstein 
2819641f2dSScott Bauer enum opal_user {
2919641f2dSScott Bauer 	OPAL_ADMIN1 = 0x0,
3019641f2dSScott Bauer 	OPAL_USER1 = 0x01,
3119641f2dSScott Bauer 	OPAL_USER2 = 0x02,
3219641f2dSScott Bauer 	OPAL_USER3 = 0x03,
3319641f2dSScott Bauer 	OPAL_USER4 = 0x04,
3419641f2dSScott Bauer 	OPAL_USER5 = 0x05,
3519641f2dSScott Bauer 	OPAL_USER6 = 0x06,
3619641f2dSScott Bauer 	OPAL_USER7 = 0x07,
3719641f2dSScott Bauer 	OPAL_USER8 = 0x08,
3819641f2dSScott Bauer 	OPAL_USER9 = 0x09,
3919641f2dSScott Bauer };
4019641f2dSScott Bauer 
4119641f2dSScott Bauer enum opal_lock_state {
4219641f2dSScott Bauer 	OPAL_RO = 0x01, /* 0001 */
4319641f2dSScott Bauer 	OPAL_RW = 0x02, /* 0010 */
4419641f2dSScott Bauer 	OPAL_LK = 0x04, /* 0100 */
4519641f2dSScott Bauer };
4619641f2dSScott Bauer 
47c1f480b2SLuca Boccassi enum opal_lock_flags {
48c1f480b2SLuca Boccassi 	/* IOC_OPAL_SAVE will also store the provided key for locking */
49c1f480b2SLuca Boccassi 	OPAL_SAVE_FOR_LOCK = 0x01,
50c1f480b2SLuca Boccassi };
51c1f480b2SLuca Boccassi 
52*3bfeb612SGreg Joyce enum opal_key_type {
53*3bfeb612SGreg Joyce 	OPAL_INCLUDED = 0,	/* key[] is the key */
54*3bfeb612SGreg Joyce 	OPAL_KEYRING,		/* key is in keyring */
55*3bfeb612SGreg Joyce };
56*3bfeb612SGreg Joyce 
5719641f2dSScott Bauer struct opal_key {
588c87fe72SScott Bauer 	__u8 lr;
598c87fe72SScott Bauer 	__u8 key_len;
60*3bfeb612SGreg Joyce 	__u8 key_type;
61*3bfeb612SGreg Joyce 	__u8 __align[5];
628c87fe72SScott Bauer 	__u8 key[OPAL_KEY_MAX];
6319641f2dSScott Bauer };
6419641f2dSScott Bauer 
655c82efc1SGreg Joyce enum opal_revert_lsp_opts {
665c82efc1SGreg Joyce 	OPAL_PRESERVE = 0x01,
675c82efc1SGreg Joyce };
685c82efc1SGreg Joyce 
6919641f2dSScott Bauer struct opal_lr_act {
7019641f2dSScott Bauer 	struct opal_key key;
718c87fe72SScott Bauer 	__u32 sum;
728c87fe72SScott Bauer 	__u8 num_lrs;
738c87fe72SScott Bauer 	__u8 lr[OPAL_MAX_LRS];
748c87fe72SScott Bauer 	__u8 align[2]; /* Align to 8 byte boundary */
7519641f2dSScott Bauer };
7619641f2dSScott Bauer 
7719641f2dSScott Bauer struct opal_session_info {
788c87fe72SScott Bauer 	__u32 sum;
798c87fe72SScott Bauer 	__u32 who;
8019641f2dSScott Bauer 	struct opal_key opal_key;
8119641f2dSScott Bauer };
8219641f2dSScott Bauer 
8319641f2dSScott Bauer struct opal_user_lr_setup {
848c87fe72SScott Bauer 	__u64 range_start;
858c87fe72SScott Bauer 	__u64 range_length;
868c87fe72SScott Bauer 	__u32 RLE; /* Read Lock enabled */
878c87fe72SScott Bauer 	__u32 WLE; /* Write Lock Enabled */
8819641f2dSScott Bauer 	struct opal_session_info session;
8919641f2dSScott Bauer };
9019641f2dSScott Bauer 
914c4dd04eSOndrej Kozina struct opal_lr_status {
924c4dd04eSOndrej Kozina 	struct opal_session_info session;
934c4dd04eSOndrej Kozina 	__u64 range_start;
944c4dd04eSOndrej Kozina 	__u64 range_length;
954c4dd04eSOndrej Kozina 	__u32 RLE; /* Read Lock enabled */
964c4dd04eSOndrej Kozina 	__u32 WLE; /* Write Lock Enabled */
974c4dd04eSOndrej Kozina 	__u32 l_state;
984c4dd04eSOndrej Kozina 	__u8  align[4];
994c4dd04eSOndrej Kozina };
1004c4dd04eSOndrej Kozina 
10119641f2dSScott Bauer struct opal_lock_unlock {
10219641f2dSScott Bauer 	struct opal_session_info session;
1038c87fe72SScott Bauer 	__u32 l_state;
104c1f480b2SLuca Boccassi 	__u16 flags;
105c1f480b2SLuca Boccassi 	__u8 __align[2];
10619641f2dSScott Bauer };
10719641f2dSScott Bauer 
10819641f2dSScott Bauer struct opal_new_pw {
10919641f2dSScott Bauer 	struct opal_session_info session;
11019641f2dSScott Bauer 
11119641f2dSScott Bauer 	/* When we're not operating in sum, and we first set
11219641f2dSScott Bauer 	 * passwords we need to set them via ADMIN authority.
11319641f2dSScott Bauer 	 * After passwords are changed, we can set them via,
11419641f2dSScott Bauer 	 * User authorities.
11519641f2dSScott Bauer 	 * Because of this restriction we need to know about
11619641f2dSScott Bauer 	 * Two different users. One in 'session' which we will use
11719641f2dSScott Bauer 	 * to start the session and new_userr_pw as the user we're
11819641f2dSScott Bauer 	 * chaning the pw for.
11919641f2dSScott Bauer 	 */
12019641f2dSScott Bauer 	struct opal_session_info new_user_pw;
12119641f2dSScott Bauer };
12219641f2dSScott Bauer 
12319641f2dSScott Bauer struct opal_mbr_data {
12419641f2dSScott Bauer 	struct opal_key key;
1258c87fe72SScott Bauer 	__u8 enable_disable;
1268c87fe72SScott Bauer 	__u8 __align[7];
12719641f2dSScott Bauer };
12819641f2dSScott Bauer 
129c9888443SJonas Rabenstein struct opal_mbr_done {
130c9888443SJonas Rabenstein 	struct opal_key key;
131c9888443SJonas Rabenstein 	__u8 done_flag;
132c9888443SJonas Rabenstein 	__u8 __align[7];
133c9888443SJonas Rabenstein };
134c9888443SJonas Rabenstein 
135a9b25b4cSJonas Rabenstein struct opal_shadow_mbr {
136a9b25b4cSJonas Rabenstein 	struct opal_key key;
137a9b25b4cSJonas Rabenstein 	const __u64 data;
138a9b25b4cSJonas Rabenstein 	__u64 offset;
139a9b25b4cSJonas Rabenstein 	__u64 size;
140a9b25b4cSJonas Rabenstein };
141a9b25b4cSJonas Rabenstein 
14251f421c8SRevanth Rajashekar /* Opal table operations */
14351f421c8SRevanth Rajashekar enum opal_table_ops {
14451f421c8SRevanth Rajashekar 	OPAL_READ_TABLE,
14551f421c8SRevanth Rajashekar 	OPAL_WRITE_TABLE,
14651f421c8SRevanth Rajashekar };
14751f421c8SRevanth Rajashekar 
14851f421c8SRevanth Rajashekar #define OPAL_UID_LENGTH 8
14951f421c8SRevanth Rajashekar struct opal_read_write_table {
15051f421c8SRevanth Rajashekar 	struct opal_key key;
15151f421c8SRevanth Rajashekar 	const __u64 data;
15251f421c8SRevanth Rajashekar 	const __u8 table_uid[OPAL_UID_LENGTH];
15351f421c8SRevanth Rajashekar 	__u64 offset;
15451f421c8SRevanth Rajashekar 	__u64 size;
15551f421c8SRevanth Rajashekar #define OPAL_TABLE_READ (1 << OPAL_READ_TABLE)
15651f421c8SRevanth Rajashekar #define OPAL_TABLE_WRITE (1 << OPAL_WRITE_TABLE)
15751f421c8SRevanth Rajashekar 	__u64 flags;
15851f421c8SRevanth Rajashekar 	__u64 priv;
15951f421c8SRevanth Rajashekar };
16051f421c8SRevanth Rajashekar 
161c6ea7060Sdougmill@linux.vnet.ibm.com #define OPAL_FL_SUPPORTED		0x00000001
162c6ea7060Sdougmill@linux.vnet.ibm.com #define OPAL_FL_LOCKING_SUPPORTED	0x00000002
163c6ea7060Sdougmill@linux.vnet.ibm.com #define OPAL_FL_LOCKING_ENABLED		0x00000004
164c6ea7060Sdougmill@linux.vnet.ibm.com #define OPAL_FL_LOCKED			0x00000008
165c6ea7060Sdougmill@linux.vnet.ibm.com #define OPAL_FL_MBR_ENABLED		0x00000010
166c6ea7060Sdougmill@linux.vnet.ibm.com #define OPAL_FL_MBR_DONE		0x00000020
1679ec041eaSLuca Boccassi #define OPAL_FL_SUM_SUPPORTED		0x00000040
168c6ea7060Sdougmill@linux.vnet.ibm.com 
169c6ea7060Sdougmill@linux.vnet.ibm.com struct opal_status {
170c6ea7060Sdougmill@linux.vnet.ibm.com 	__u32 flags;
171c6ea7060Sdougmill@linux.vnet.ibm.com 	__u32 reserved;
172c6ea7060Sdougmill@linux.vnet.ibm.com };
173c6ea7060Sdougmill@linux.vnet.ibm.com 
1749e05a259SOndrej Kozina /*
1759e05a259SOndrej Kozina  * Geometry Reporting per TCG Storage OPAL SSC
1769e05a259SOndrej Kozina  * section 3.1.1.4
1779e05a259SOndrej Kozina  */
1789e05a259SOndrej Kozina struct opal_geometry {
1799e05a259SOndrej Kozina 	__u8 align;
1809e05a259SOndrej Kozina 	__u32 logical_block_size;
1819e05a259SOndrej Kozina 	__u64 alignment_granularity;
1829e05a259SOndrej Kozina 	__u64 lowest_aligned_lba;
1839e05a259SOndrej Kozina 	__u8  __align[3];
1849e05a259SOndrej Kozina };
1859e05a259SOndrej Kozina 
1869fb10726SGreg Joyce struct opal_discovery {
1879fb10726SGreg Joyce 	__u64 data;
1889fb10726SGreg Joyce 	__u64 size;
1899fb10726SGreg Joyce };
1909fb10726SGreg Joyce 
1915c82efc1SGreg Joyce struct opal_revert_lsp {
1925c82efc1SGreg Joyce 	struct opal_key key;
1935c82efc1SGreg Joyce 	__u32 options;
1945c82efc1SGreg Joyce 	__u32 __pad;
1955c82efc1SGreg Joyce };
1965c82efc1SGreg Joyce 
19719641f2dSScott Bauer #define IOC_OPAL_SAVE		    _IOW('p', 220, struct opal_lock_unlock)
19819641f2dSScott Bauer #define IOC_OPAL_LOCK_UNLOCK	    _IOW('p', 221, struct opal_lock_unlock)
19919641f2dSScott Bauer #define IOC_OPAL_TAKE_OWNERSHIP	    _IOW('p', 222, struct opal_key)
20024bff4d7SScott Bauer #define IOC_OPAL_ACTIVATE_LSP       _IOW('p', 223, struct opal_lr_act)
20119641f2dSScott Bauer #define IOC_OPAL_SET_PW             _IOW('p', 224, struct opal_new_pw)
20219641f2dSScott Bauer #define IOC_OPAL_ACTIVATE_USR       _IOW('p', 225, struct opal_session_info)
20319641f2dSScott Bauer #define IOC_OPAL_REVERT_TPR         _IOW('p', 226, struct opal_key)
20419641f2dSScott Bauer #define IOC_OPAL_LR_SETUP           _IOW('p', 227, struct opal_user_lr_setup)
20519641f2dSScott Bauer #define IOC_OPAL_ADD_USR_TO_LR      _IOW('p', 228, struct opal_lock_unlock)
20619641f2dSScott Bauer #define IOC_OPAL_ENABLE_DISABLE_MBR _IOW('p', 229, struct opal_mbr_data)
20719641f2dSScott Bauer #define IOC_OPAL_ERASE_LR           _IOW('p', 230, struct opal_session_info)
20819641f2dSScott Bauer #define IOC_OPAL_SECURE_ERASE_LR    _IOW('p', 231, struct opal_session_info)
2095e4c7cf6SRevanth Rajashekar #define IOC_OPAL_PSID_REVERT_TPR    _IOW('p', 232, struct opal_key)
210c9888443SJonas Rabenstein #define IOC_OPAL_MBR_DONE           _IOW('p', 233, struct opal_mbr_done)
211a9b25b4cSJonas Rabenstein #define IOC_OPAL_WRITE_SHADOW_MBR   _IOW('p', 234, struct opal_shadow_mbr)
21251f421c8SRevanth Rajashekar #define IOC_OPAL_GENERIC_TABLE_RW   _IOW('p', 235, struct opal_read_write_table)
213c6ea7060Sdougmill@linux.vnet.ibm.com #define IOC_OPAL_GET_STATUS         _IOR('p', 236, struct opal_status)
2144c4dd04eSOndrej Kozina #define IOC_OPAL_GET_LR_STATUS      _IOW('p', 237, struct opal_lr_status)
2159e05a259SOndrej Kozina #define IOC_OPAL_GET_GEOMETRY       _IOR('p', 238, struct opal_geometry)
2169fb10726SGreg Joyce #define IOC_OPAL_DISCOVERY          _IOW('p', 239, struct opal_discovery)
2175c82efc1SGreg Joyce #define IOC_OPAL_REVERT_LSP         _IOW('p', 240, struct opal_revert_lsp)
21819641f2dSScott Bauer 
21919641f2dSScott Bauer #endif /* _UAPI_SED_OPAL_H */
220