xref: /linux/include/uapi/linux/sed-opal.h (revision 7fe6ac157b7e15c8976bd62ad7cb98e248884e83)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
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 
10 #ifndef _UAPI_SED_OPAL_H
11 #define _UAPI_SED_OPAL_H
12 
13 #include <linux/types.h>
14 
15 #define OPAL_KEY_MAX 256
16 #define OPAL_MAX_LRS 9
17 
18 enum opal_mbr {
19 	OPAL_MBR_ENABLE = 0x0,
20 	OPAL_MBR_DISABLE = 0x01,
21 };
22 
23 enum opal_mbr_done_flag {
24 	OPAL_MBR_NOT_DONE = 0x0,
25 	OPAL_MBR_DONE = 0x01
26 };
27 
28 enum opal_user {
29 	OPAL_ADMIN1 = 0x0,
30 	OPAL_USER1 = 0x01,
31 	OPAL_USER2 = 0x02,
32 	OPAL_USER3 = 0x03,
33 	OPAL_USER4 = 0x04,
34 	OPAL_USER5 = 0x05,
35 	OPAL_USER6 = 0x06,
36 	OPAL_USER7 = 0x07,
37 	OPAL_USER8 = 0x08,
38 	OPAL_USER9 = 0x09,
39 };
40 
41 enum opal_lock_state {
42 	OPAL_RO = 0x01, /* 0001 */
43 	OPAL_RW = 0x02, /* 0010 */
44 	OPAL_LK = 0x04, /* 0100 */
45 };
46 
47 enum opal_lock_flags {
48 	/* IOC_OPAL_SAVE will also store the provided key for locking */
49 	OPAL_SAVE_FOR_LOCK = 0x01,
50 };
51 
52 enum opal_key_type {
53 	OPAL_INCLUDED = 0,	/* key[] is the key */
54 	OPAL_KEYRING,		/* key is in keyring */
55 };
56 
57 struct opal_key {
58 	__u8 lr;
59 	__u8 key_len;
60 	__u8 key_type;
61 	__u8 __align[5];
62 	__u8 key[OPAL_KEY_MAX];
63 };
64 
65 enum opal_revert_lsp_opts {
66 	OPAL_PRESERVE = 0x01,
67 };
68 
69 struct opal_lr_act {
70 	struct opal_key key;
71 	__u32 sum;
72 	__u8 num_lrs;
73 	__u8 lr[OPAL_MAX_LRS];
74 	__u8 align[2]; /* Align to 8 byte boundary */
75 };
76 
77 struct opal_lr_react {
78 	struct opal_key key;
79 	struct opal_key new_admin_key; /* Set new Admin1 PIN if key_len is > 0 */
80 	__u8 num_lrs; /*
81 		       * Configure selected ranges (from lr[]) in SUM.
82 		       * If num_lrs > 0 the 'entire_table' must be 0
83 		       */
84 	__u8 lr[OPAL_MAX_LRS];
85 	__u8 range_policy; /* Set RangeStartRangeLengthPolicy parameter */
86 	__u8 entire_table; /* Set all locking objects in SUM */
87 	__u8 align[4]; /* Align to 8 byte boundary */
88 };
89 
90 struct opal_session_info {
91 	__u32 sum;
92 	__u32 who;
93 	struct opal_key opal_key;
94 };
95 
96 struct opal_user_lr_setup {
97 	__u64 range_start;
98 	__u64 range_length;
99 	__u32 RLE; /* Read Lock enabled */
100 	__u32 WLE; /* Write Lock Enabled */
101 	struct opal_session_info session;
102 };
103 
104 struct opal_lr_status {
105 	struct opal_session_info session;
106 	__u64 range_start;
107 	__u64 range_length;
108 	__u32 RLE; /* Read Lock enabled */
109 	__u32 WLE; /* Write Lock Enabled */
110 	__u32 l_state;
111 	__u8  align[4];
112 };
113 
114 struct opal_sum_ranges {
115 	/*
116 	 * Initiate Admin1 session if key_len > 0,
117 	 * use Anybody session otherwise.
118 	 */
119 	struct opal_key key;
120 	__u8 num_lrs;
121 	__u8 lr[OPAL_MAX_LRS];
122 	__u8 range_policy;
123 	__u8 align[5]; /* Align to 8 byte boundary */
124 };
125 
126 struct opal_lock_unlock {
127 	struct opal_session_info session;
128 	__u32 l_state;
129 	__u16 flags;
130 	__u8 __align[2];
131 };
132 
133 struct opal_new_pw {
134 	struct opal_session_info session;
135 
136 	/* When we're not operating in sum, and we first set
137 	 * passwords we need to set them via ADMIN authority.
138 	 * After passwords are changed, we can set them via,
139 	 * User authorities.
140 	 * Because of this restriction we need to know about
141 	 * Two different users. One in 'session' which we will use
142 	 * to start the session and new_userr_pw as the user we're
143 	 * chaning the pw for.
144 	 */
145 	struct opal_session_info new_user_pw;
146 };
147 
148 struct opal_mbr_data {
149 	struct opal_key key;
150 	__u8 enable_disable;
151 	__u8 __align[7];
152 };
153 
154 struct opal_mbr_done {
155 	struct opal_key key;
156 	__u8 done_flag;
157 	__u8 __align[7];
158 };
159 
160 struct opal_shadow_mbr {
161 	struct opal_key key;
162 	const __u64 data;
163 	__u64 offset;
164 	__u64 size;
165 };
166 
167 /* Opal table operations */
168 enum opal_table_ops {
169 	OPAL_READ_TABLE,
170 	OPAL_WRITE_TABLE,
171 };
172 
173 #define OPAL_UID_LENGTH 8
174 struct opal_read_write_table {
175 	struct opal_key key;
176 	const __u64 data;
177 	const __u8 table_uid[OPAL_UID_LENGTH];
178 	__u64 offset;
179 	__u64 size;
180 #define OPAL_TABLE_READ (1 << OPAL_READ_TABLE)
181 #define OPAL_TABLE_WRITE (1 << OPAL_WRITE_TABLE)
182 	__u64 flags;
183 	__u64 priv;
184 };
185 
186 #define OPAL_FL_SUPPORTED		0x00000001
187 #define OPAL_FL_LOCKING_SUPPORTED	0x00000002
188 #define OPAL_FL_LOCKING_ENABLED		0x00000004
189 #define OPAL_FL_LOCKED			0x00000008
190 #define OPAL_FL_MBR_ENABLED		0x00000010
191 #define OPAL_FL_MBR_DONE		0x00000020
192 #define OPAL_FL_SUM_SUPPORTED		0x00000040
193 
194 struct opal_status {
195 	__u32 flags;
196 	__u32 reserved;
197 };
198 
199 /*
200  * Geometry Reporting per TCG Storage OPAL SSC
201  * section 3.1.1.4
202  */
203 struct opal_geometry {
204 	__u8 align;
205 	__u32 logical_block_size;
206 	__u64 alignment_granularity;
207 	__u64 lowest_aligned_lba;
208 	__u8  __align[3];
209 };
210 
211 struct opal_discovery {
212 	__u64 data;
213 	__u64 size;
214 };
215 
216 struct opal_revert_lsp {
217 	struct opal_key key;
218 	__u32 options;
219 	__u32 __pad;
220 };
221 
222 #define IOC_OPAL_SAVE		    _IOW('p', 220, struct opal_lock_unlock)
223 #define IOC_OPAL_LOCK_UNLOCK	    _IOW('p', 221, struct opal_lock_unlock)
224 #define IOC_OPAL_TAKE_OWNERSHIP	    _IOW('p', 222, struct opal_key)
225 #define IOC_OPAL_ACTIVATE_LSP       _IOW('p', 223, struct opal_lr_act)
226 #define IOC_OPAL_SET_PW             _IOW('p', 224, struct opal_new_pw)
227 #define IOC_OPAL_ACTIVATE_USR       _IOW('p', 225, struct opal_session_info)
228 #define IOC_OPAL_REVERT_TPR         _IOW('p', 226, struct opal_key)
229 #define IOC_OPAL_LR_SETUP           _IOW('p', 227, struct opal_user_lr_setup)
230 #define IOC_OPAL_ADD_USR_TO_LR      _IOW('p', 228, struct opal_lock_unlock)
231 #define IOC_OPAL_ENABLE_DISABLE_MBR _IOW('p', 229, struct opal_mbr_data)
232 #define IOC_OPAL_ERASE_LR           _IOW('p', 230, struct opal_session_info)
233 #define IOC_OPAL_SECURE_ERASE_LR    _IOW('p', 231, struct opal_session_info)
234 #define IOC_OPAL_PSID_REVERT_TPR    _IOW('p', 232, struct opal_key)
235 #define IOC_OPAL_MBR_DONE           _IOW('p', 233, struct opal_mbr_done)
236 #define IOC_OPAL_WRITE_SHADOW_MBR   _IOW('p', 234, struct opal_shadow_mbr)
237 #define IOC_OPAL_GENERIC_TABLE_RW   _IOW('p', 235, struct opal_read_write_table)
238 #define IOC_OPAL_GET_STATUS         _IOR('p', 236, struct opal_status)
239 #define IOC_OPAL_GET_LR_STATUS      _IOW('p', 237, struct opal_lr_status)
240 #define IOC_OPAL_GET_GEOMETRY       _IOR('p', 238, struct opal_geometry)
241 #define IOC_OPAL_DISCOVERY          _IOW('p', 239, struct opal_discovery)
242 #define IOC_OPAL_REVERT_LSP         _IOW('p', 240, struct opal_revert_lsp)
243 #define IOC_OPAL_SET_SID_PW         _IOW('p', 241, struct opal_new_pw)
244 #define IOC_OPAL_REACTIVATE_LSP     _IOW('p', 242, struct opal_lr_react)
245 #define IOC_OPAL_LR_SET_START_LEN   _IOW('p', 243, struct opal_user_lr_setup)
246 #define IOC_OPAL_ENABLE_DISABLE_LR  _IOW('p', 244, struct opal_user_lr_setup)
247 #define IOC_OPAL_GET_SUM_STATUS     _IOW('p', 245, struct opal_sum_ranges)
248 #define IOC_OPAL_STACK_RESET        _IO('p', 246)
249 
250 #endif /* _UAPI_SED_OPAL_H */
251