]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/lib/nvme/nvme_opal_internal.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / lib / nvme / nvme_opal_internal.h
CommitLineData
9f95a23c
TL
1/*-
2 * BSD LICENSE
3 *
4 * Copyright (c) Intel Corporation.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#ifndef SPDK_OPAL_INTERNAL_H
35#define SPDK_OPAL_INTERNAL_H
36
37#include "spdk/opal_spec.h"
38#include "spdk/opal.h"
39#include "spdk/scsi_spec.h"
40
41#define IO_BUFFER_LENGTH 2048
42#define MAX_TOKS 64
43#define OPAL_KEY_MAX 256
44#define OPAL_UID_LENGTH 8
9f95a23c
TL
45
46#define GENERIC_HOST_SESSION_NUM 0x69
47
48#define OPAL_INVAL_PARAM 12
49
50#define SPDK_DTAERROR_NO_METHOD_STATUS 0x89
51
52enum opal_token_type {
53 OPAL_DTA_TOKENID_BYTESTRING = 0xE0,
54 OPAL_DTA_TOKENID_SINT = 0xE1,
55 OPAL_DTA_TOKENID_UINT = 0xE2,
56 OPAL_DTA_TOKENID_TOKEN = 0xE3, /* actual token is returned */
57 OPAL_DTA_TOKENID_INVALID = 0X0,
58};
59
60enum opal_atom_width {
61 OPAL_WIDTH_TINY, /* 1 byte in length */
62 OPAL_WIDTH_SHORT, /* a 1-byte header and contain up to 15 bytes of data */
63 OPAL_WIDTH_MEDIUM, /* a 2-byte header and contain up to 2047 bytes of data */
64 OPAL_WIDTH_LONG, /* a 4-byte header and which contain up to 16,777,215 bytes of data */
65 OPAL_WIDTH_TOKEN
66};
67
68enum opal_uid_enum {
69 /* users */
70 UID_SMUID,
71 UID_THISSP,
72 UID_ADMINSP,
73 UID_LOCKINGSP,
74 UID_ANYBODY,
75 UID_SID,
76 UID_ADMIN1,
77 UID_USER1,
78 UID_USER2,
79
80 /* tables */
81 UID_LOCKINGRANGE_GLOBAL,
82 UID_LOCKINGRANGE_ACE_RDLOCKED,
83 UID_LOCKINGRANGE_ACE_WRLOCKED,
84 UID_MBRCONTROL,
85 UID_MBR,
86 UID_AUTHORITY_TABLE,
87 UID_C_PIN_TABLE,
88 UID_LOCKING_INFO_TABLE,
89 UID_PSID,
90
91 /* C_PIN_TABLE object ID's */
92 UID_C_PIN_MSID,
93 UID_C_PIN_SID,
94 UID_C_PIN_ADMIN1,
95 UID_C_PIN_USER1,
96
97 /* half UID's (only first 4 bytes used) */
98 UID_HALF_AUTHORITY_OBJ_REF,
99 UID_HALF_BOOLEAN_ACE,
100};
101
102/* enum for indexing the spdk_opal_method array */
103enum opal_method_enum {
104 PROPERTIES_METHOD,
105 STARTSESSION_METHOD,
106 REVERT_METHOD,
107 ACTIVATE_METHOD,
108 NEXT_METHOD,
109 GETACL_METHOD,
110 GENKEY_METHOD,
111 REVERTSP_METHOD,
112 GET_METHOD,
113 SET_METHOD,
114 AUTHENTICATE_METHOD,
115 RANDOM_METHOD,
f67539c2 116 ERASE_METHOD,
9f95a23c
TL
117};
118
f67539c2
TL
119struct spdk_opal_key {
120 uint8_t key_len;
121 uint8_t key[OPAL_KEY_MAX];
9f95a23c
TL
122};
123
124const uint8_t spdk_opal_uid[][OPAL_UID_LENGTH] = {
125 /* users */
126 [UID_SMUID] = /* Session Manager UID */
127 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff },
128 [UID_THISSP] =
129 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
130 [UID_ADMINSP] =
131 { 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00, 0x01 },
132 [UID_LOCKINGSP] =
133 { 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00, 0x02 },
134 [UID_ANYBODY] =
135 { 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x01 },
136 [UID_SID] = /* Security Identifier UID */
137 { 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x06 },
138 [UID_ADMIN1] =
139 { 0x00, 0x00, 0x00, 0x09, 0x00, 0x01, 0x00, 0x01 },
140 [UID_USER1] =
141 { 0x00, 0x00, 0x00, 0x09, 0x00, 0x03, 0x00, 0x01 },
142 [UID_USER2] =
143 { 0x00, 0x00, 0x00, 0x09, 0x00, 0x03, 0x00, 0x02 },
144
145 /* tables */
146 [UID_LOCKINGRANGE_GLOBAL] =
147 { 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00, 0x01 },
148 [UID_LOCKINGRANGE_ACE_RDLOCKED] =
149 { 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0xE0, 0x01 },
150 [UID_LOCKINGRANGE_ACE_WRLOCKED] =
151 { 0x00, 0x00, 0x00, 0x08, 0x00, 0x03, 0xE8, 0x01 },
152 [UID_MBRCONTROL] =
153 { 0x00, 0x00, 0x08, 0x03, 0x00, 0x00, 0x00, 0x01 },
154 [UID_MBR] =
155 { 0x00, 0x00, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00 },
156 [UID_AUTHORITY_TABLE] =
157 { 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00},
158 [UID_C_PIN_TABLE] =
159 { 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x00},
160 [UID_LOCKING_INFO_TABLE] =
161 { 0x00, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x01 },
162 [UID_PSID] =
163 { 0x00, 0x00, 0x00, 0x09, 0x00, 0x01, 0xff, 0x01 },
164
165 /* C_PIN_TABLE object ID's */
166 [UID_C_PIN_MSID] =
167 { 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x84, 0x02},
168 [UID_C_PIN_SID] =
169 { 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x01},
170 [UID_C_PIN_ADMIN1] =
171 { 0x00, 0x00, 0x00, 0x0B, 0x00, 0x01, 0x00, 0x01},
172 [UID_C_PIN_USER1] =
173 { 0x00, 0x00, 0x00, 0x0B, 0x00, 0x03, 0x00, 0x01},
174
175 /* half UID's (only first 4 bytes used) */
176 [UID_HALF_AUTHORITY_OBJ_REF] =
177 { 0x00, 0x00, 0x0C, 0x05, 0xff, 0xff, 0xff, 0xff },
178 [UID_HALF_BOOLEAN_ACE] =
179 { 0x00, 0x00, 0x04, 0x0E, 0xff, 0xff, 0xff, 0xff },
180};
181
182/*
183 * TCG Storage SSC Methods.
184 */
185const uint8_t spdk_opal_method[][OPAL_UID_LENGTH] = {
186 [PROPERTIES_METHOD] =
187 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01 },
188 [STARTSESSION_METHOD] =
189 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x02 },
190 [REVERT_METHOD] =
191 { 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x02, 0x02 },
192 [ACTIVATE_METHOD] =
193 { 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x02, 0x03 },
194 [NEXT_METHOD] =
195 { 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x08 },
196 [GETACL_METHOD] =
197 { 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0d },
198 [GENKEY_METHOD] =
199 { 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10 },
200 [REVERTSP_METHOD] =
201 { 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x11 },
202 [GET_METHOD] =
203 { 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x16 },
204 [SET_METHOD] =
205 { 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x17 },
206 [AUTHENTICATE_METHOD] =
207 { 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x1c },
208 [RANDOM_METHOD] =
209 { 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x01 },
f67539c2
TL
210 [ERASE_METHOD] =
211 { 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x08, 0x03 },
9f95a23c
TL
212};
213
214/*
215 * Response token
216 */
217struct spdk_opal_resp_token {
218 const uint8_t *pos;
219 uint8_t _padding[7];
220 union {
221 uint64_t unsigned_num;
222 int64_t signed_num;
223 } stored;
224 size_t len; /* header + data */
225 enum opal_token_type type;
226 enum opal_atom_width width;
227};
228
229struct spdk_opal_resp_parsed {
230 int num;
231 struct spdk_opal_resp_token resp_tokens[MAX_TOKS];
232};
233
9f95a23c
TL
234/* header of a response */
235struct spdk_opal_header {
236 struct spdk_opal_compacket com_packet;
237 struct spdk_opal_packet packet;
238 struct spdk_opal_data_subpacket sub_packet;
239};
240
f67539c2
TL
241struct opal_session;
242struct spdk_opal_dev;
9f95a23c 243
f67539c2
TL
244typedef void (*opal_sess_cb)(struct opal_session *sess, int status, void *ctx);
245
246struct opal_session {
9f95a23c
TL
247 uint32_t hsn;
248 uint32_t tsn;
9f95a23c
TL
249 size_t cmd_pos;
250 uint8_t cmd[IO_BUFFER_LENGTH];
251 uint8_t resp[IO_BUFFER_LENGTH];
9f95a23c 252 struct spdk_opal_resp_parsed parsed_resp;
9f95a23c 253
f67539c2
TL
254 opal_sess_cb sess_cb;
255 void *cb_arg;
256 bool done;
257 int status;
258 struct spdk_opal_dev *dev;
259};
9f95a23c 260
f67539c2
TL
261struct spdk_opal_dev {
262 struct spdk_nvme_ctrlr *ctrlr;
263
264 uint16_t comid;
9f95a23c 265
f67539c2 266 struct spdk_opal_d0_features_info feat_info;
9f95a23c 267
f67539c2
TL
268 uint8_t max_ranges; /* max locking range number */
269 struct spdk_opal_locking_range_info locking_ranges[SPDK_OPAL_MAX_LOCKING_RANGE];
9f95a23c
TL
270};
271
272#endif