forked from snu-csl/nvmevirt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
nvme_kv.h
291 lines (268 loc) · 5.26 KB
/
nvme_kv.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
// SPDX-License-Identifier: GPL-2.0-only
#ifndef _NVME_KV_H
#define _NVME_KV_H
#include "nvme.h"
enum nvme_opcode_kv {
nvme_cmd_kv_store = 0x81,
nvme_cmd_kv_append = 0x83,
nvme_cmd_kv_retrieve = 0x90,
nvme_cmd_kv_delete = 0xA1,
nvme_cmd_kv_iter_req = 0xB1,
nvme_cmd_kv_iter_read = 0xB2,
nvme_cmd_kv_exist = 0xB3,
nvme_cmd_kv_batch = 0x85,
};
#define KVCMD_INLINE_KEY_MAX (16)
#define KVCMD_MAX_KEY_SIZE (255)
#define KVCMD_MIN_KEY_SIZE (4)
#define MAX_SUB_CMD (8)
#define ALIGN_LEN (64)
union nvme_data_ptr {
struct {
__le64 prp1;
__le64 prp2;
};
};
/*KV-SSD Command*/
struct nvme_kv_store_command {
__u8 opcode;
__u8 flags;
__u16 command_id;
__le32 nsid;
__u64 rsvd;
__le32 offset;
__u32 rsvd2;
union nvme_data_ptr dptr; /* value dptr prp1,2 */
__le32 value_len; /* size in word */
__u8 key_len; /* 0 ~ 255 (keylen - 1) */
__u8 option;
__u8 invalid_byte : 2;
__u8 rsvd3 : 6;
__u8 rsvd4;
union {
struct {
char key[16];
};
struct {
__le64 key_prp;
__le64 key_prp2;
};
};
};
struct nvme_kv_append_command {
__u8 opcode;
__u8 flags;
__u16 command_id;
__le32 nsid;
__u64 rsvd;
__le32 offset;
__u32 rsvd2;
union nvme_data_ptr dptr; /* value dptr prp1,2 */
__le32 value_len; /* size in word */
__u8 key_len; /* 0 ~ 255 (keylen - 1) */
__u8 option;
__u8 invalid_byte : 2;
__u8 rsvd3 : 6;
__u8 rsvd4;
union {
struct {
char key[16];
};
struct {
__le64 key_prp;
__le64 key_prp2;
};
};
};
struct nvme_kv_batch_command {
__u8 opcode;
__u8 flags;
__u16 command_id;
__le32 nsid;
__u64 rsvd;
__le32 offset;
__u32 rsvd2;
union nvme_data_ptr dptr; /* value dptr prp1,2 */
__le32 value_len; /* size in word */
__u8 key_len; /* 0 ~ 255 (key len -1) */
__u8 option;
__u8 rsvd3;
__u8 rsvd4;
union {
struct {
char key[16];
};
struct {
__le64 key_prp;
__le64 key_prp2;
};
};
};
struct nvme_kv_retrieve_command {
__u8 opcode;
__u8 flags;
__u16 command_id;
__le32 nsid;
__u64 rsvd;
__le32 offset;
__u32 rsvd2;
union nvme_data_ptr dptr; /* value dptr prp1,2 */
__le32 value_len; /* size in word */
__u8 key_len; /* 0 ~ 255 (keylen - 1) */
__u8 option;
__u16 rsvd3;
union {
struct {
char key[16];
};
struct {
__le64 key_prp;
__le64 key_prp2;
};
};
};
struct nvme_kv_delete_command {
__u8 opcode;
__u8 flags;
__u16 command_id;
__le32 nsid;
__u64 rsvd;
__le32 offset;
__u32 rsvd2;
__u64 rsvd3[2];
__le32 value_len; /* size in word */
__u8 key_len; /* 0 ~ 255 (keylen - 1) */
__u8 option;
__u16 rsvd4;
union {
struct {
char key[16];
};
struct {
__le64 key_prp;
__le64 key_prp2;
};
};
};
struct nvme_kv_iter_req_command {
__u8 opcode;
__u8 flags;
__u16 command_id;
__le32 nsid;
__u64 rsvd[4];
__le32 zero; /* should be zero */
__u8 iter_handle;
__u8 option;
__u16 rsvd2;
__u32 iter_val;
__u32 iter_bitmask;
__u64 rsvd3;
};
struct nvme_kv_iter_read_command {
__u8 opcode;
__u8 flags;
__u16 command_id;
__le32 nsid;
__u64 rsvd[2];
union nvme_data_ptr dptr; /* value dptr prp1,2 */
__le32 value_len; /* size in word */
__u8 iter_handle;
__u8 option;
__u16 rsvd2;
__u64 rsvd3[2];
};
struct nvme_kv_exist_command {
__u8 opcode;
__u8 flags;
__u16 command_id;
__le32 nsid;
__u64 rsvd;
__le32 offset;
__u32 rsvd2;
__u64 rsvd3[2];
__le32 value_len; /* size in word */
__u8 key_len; /* 0 ~ 255 (keylen - 1) */
__u8 option;
__u16 rsvd4;
union {
struct {
char key[16];
};
struct {
__le64 key_prp;
__le64 key_prp2;
};
};
};
/* Additional structures for iterator */
struct kv_iter_context {
unsigned char handle;
unsigned int prefix;
unsigned int bitmask;
void *buf;
int buflen;
int byteswritten;
int bufoffset;
bool end;
unsigned long current_pos;
};
enum nvme_kv_iter_req_option {
ITER_OPTION_NOTHING = 0x0,
ITER_OPTION_OPEN = 0x01,
ITER_OPTION_CLOSE = 0x02,
ITER_OPTION_KEY_ONLY = 0x04,
ITER_OPTION_KEY_VALUE = 0x08,
ITER_OPTION_DEL_KEY_VALUE = 0x10,
};
/* Additional structures for batch */
struct sub_cmd_attribute {
__u8 opcode; // DW0 support only 0x81 and 0xA0
__u8 keySize; // DW0 [15:08] Keys size
__u8 reservedDw0[2]; // DW0 [31:16] Reserved
__u32 valueSize; // DW1 Value size
__u8 option; // DW2 [07:00] Option. Follow the command option definition corresponding to the sub command opcode.
__u8 nsid; // DW2 [15:08] Key space ID
__u8 reservedDw2[2]; // DW2 [31:16] Reserved
__u32 NoUsed; // DW3
};
struct batch_cmd_head {
struct sub_cmd_attribute attr[MAX_SUB_CMD];
__u8 reserved[384];
};
struct sub_cmd_head {
__u8 reserved[ALIGN_LEN];
};
struct sub_payload_format {
struct sub_cmd_head sub_head;
__u8 data[0];
};
struct payload_format {
struct batch_cmd_head batch_head;
__u8 sub_payload[0];
};
struct sub_payload_attribute {
__u32 sub_payload_len;
__u32 key_len;
__u32 value_len;
};
struct kv_batch_data {
__u8 key[256];
__u32 keySize;
__u8 value[4097];
__u32 valueSize;
__u32 opcode;
};
struct nvme_kv_command {
union {
struct nvme_common_command common;
struct nvme_kv_store_command kv_store;
struct nvme_kv_retrieve_command kv_retrieve;
struct nvme_kv_delete_command kv_delete;
struct nvme_kv_append_command kv_append;
struct nvme_kv_iter_req_command kv_iter_req;
struct nvme_kv_iter_read_command kv_iter_read;
struct nvme_kv_exist_command kv_exist;
struct nvme_kv_batch_command kv_batch;
};
};
#endif