Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
packet-nvme.h
1/* packet-nvme.h
2 * data structures for NVMe Dissection
3 * Copyright 2016
4 * Code by Parav Pandit
5 *
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 */
12#ifndef _PACKET_NVME_H_
13#define _PACKET_NVME_H_
14
15#define NVME_CMD_SIZE 64
16#define NVME_CQE_SIZE 16
17
18#define NVME_FABRIC_OPC 0x7F
19#define NVME_FCTYPE_PROP_SET 0x0
20#define NVME_FCTYPE_CONNECT 0x1
21#define NVME_FCTYPE_PROP_GET 0x4
22#define NVME_FCTYPE_AUTH_SEND 0x5
23#define NVME_FCTYPE_AUTH_RECV 0x6
24#define NVME_FCTYPE_DISCONNECT 0x8
25
26/* NVMe Admin opcodes, shared with NVMe-MI (MI 2.1 Figure 134). */
27#define NVME_AQ_OPC_DELETE_SQ 0x00
28#define NVME_AQ_OPC_CREATE_SQ 0x01
29#define NVME_AQ_OPC_GET_LOG_PAGE 0x02
30#define NVME_AQ_OPC_DELETE_CQ 0x04
31#define NVME_AQ_OPC_CREATE_CQ 0x05
32#define NVME_AQ_OPC_IDENTIFY 0x06
33#define NVME_AQ_OPC_ABORT 0x08
34#define NVME_AQ_OPC_SET_FEATURES 0x09
35#define NVME_AQ_OPC_GET_FEATURES 0x0a
36#define NVME_AQ_OPC_ASYNC_EVE_REQ 0x0c
37#define NVME_AQ_OPC_NS_MGMT 0x0d
38#define NVME_AQ_OPC_FW_COMMIT 0x10
39#define NVME_AQ_OPC_FW_IMG_DOWNLOAD 0x11
40#define NVME_AQ_OPC_SELF_TEST 0x14
41#define NVME_AQ_OPC_NS_ATTACH 0x15
42#define NVME_AQ_OPC_KEEP_ALIVE 0x18
43#define NVME_AQ_OPC_DIRECTIVE_SEND 0x19
44#define NVME_AQ_OPC_DIRECTIVE_RECV 0x1a
45#define NVME_AQ_OPC_VIRT_MGMT 0x1c
46#define NVME_AQ_OPC_MI_SEND 0x1d
47#define NVME_AQ_OPC_MI_RECV 0x1e
48#define NVME_AQ_OPC_CAP_MGMT 0x20
49#define NVME_AQ_OPC_DISC_INFO_MGMT 0x21
50#define NVME_AQ_OPC_FABRIC_ZONING_RECV 0x22
51#define NVME_AQ_OPC_LOCKDOWN 0x24
52#define NVME_AQ_OPC_FABRIC_ZONING_LOOKUP 0x25
53#define NVME_AQ_OPC_CLEAR_EXP_NVM_CFG 0x28
54#define NVME_AQ_OPC_FABRIC_ZONING_SEND 0x29
55#define NVME_AQ_OPC_CREATE_EXP_NVM_SUBSYS 0x2a
56#define NVME_AQ_OPC_MANAGE_EXP_NVM_SUBSYS 0x2d
57#define NVME_AQ_OPC_MANAGE_EXP_NS 0x31
58#define NVME_AQ_OPC_MANAGE_EXP_PORT 0x35
59#define NVME_AQ_OPC_CROSS_CTRL_RESET 0x38
60#define NVME_AQ_OPC_SEND_DISC_LOG_PAGE 0x39
61#define NVME_AQ_OPC_TRACK_SEND 0x3d
62#define NVME_AQ_OPC_TRACK_RECV 0x3e
63#define NVME_AQ_OPC_MIGRATION_SEND 0x41
64#define NVME_AQ_OPC_MIGRATION_RECV 0x42
65#define NVME_AQ_OPC_CTRL_DATA_QUEUE 0x45
66#define NVME_AQ_OPC_DBBUF_CONFIG 0x7c
67#define NVME_AQ_OPC_FORMAT_NVM 0x80
68#define NVME_AQ_OPC_SECURITY_SEND 0x81
69#define NVME_AQ_OPC_SECURITY_RECV 0x82
70#define NVME_AQ_OPC_SANITIZE 0x84
71#define NVME_AQ_OPC_LOAD_PROGRAM 0x85
72#define NVME_AQ_OPC_GET_LBA_STATUS 0x86
73#define NVME_AQ_OPC_PROG_ACTIVATION_MGMT 0x88
74#define NVME_AQ_OPC_MEM_RANGE_SET_MGMT 0x89
75#define NVME_AQ_OPC_SANITIZE_NS 0x8c
76
77#define NVME_IDENTIFY_CNS_IDENTIFY_NS 0x0
78#define NVME_IDENTIFY_CNS_IDENTIFY_CTRL 0x1
79#define NVME_IDENTIFY_CNS_IDENTIFY_NSLIST 0x2
80#define NVME_IDENTIFY_CNS_NSID_DESC_LIST 0x3
81#define NVME_IDENTIFY_CNS_NVM_SET_LIST 0x4
82#define NVME_IDENTIFY_CNS_CS_IND_NS 0x8
83#define NVME_IDENTIFY_CNS_NS_ALLOC_LIST 0x10
84#define NVME_IDENTIFY_CNS_NS_ALLOC 0x11
85#define NVME_IDENTIFY_CNS_CTRL_LIST_NS 0x12
86#define NVME_IDENTIFY_CNS_CTRL_LIST 0x13
87#define NVME_IDENTIFY_CNS_PRI_CTRL_CAP 0x14
88#define NVME_IDENTIFY_CNS_SEC_CTRL_LIST 0x15
89#define NVME_IDENTIFY_CNS_NS_GRAN_LIST 0x16
90#define NVME_IDENTIFY_CNS_UUID_LIST 0x17
91
92
93/* Provenance of data bytes: gates retaining version and log page walk state,
94 * not rendering. */
95enum nvme_data_provenance {
96 NVME_DATA_PROV_NONE = 0, /* not vouched response data: retain nothing */
97 NVME_DATA_PROV_RESPONSE, /* response data at its true logical offset */
98};
99
100/* How the caller knows the block's logical offset. */
101enum nvme_data_window {
102 NVME_DATA_WINDOW_UNKNOWN = 0, /* a guess: render, but retain nothing */
103 NVME_DATA_WINDOW_TRACKED, /* running transfer offset, recorded per frame */
104 NVME_DATA_WINDOW_EXPLICIT, /* from the transport header, in 'offset' */
105};
106
107/* Transaction half; Admin data travels one way per opcode. */
108enum nvme_data_direction {
109 NVME_DATA_DIR_HOST_TO_CONTROLLER, /* request, write, in-capsule data */
110 NVME_DATA_DIR_CONTROLLER_TO_HOST, /* response and read data */
111};
112
113/* Where the block belongs. The direction is passed separately. */
115 enum nvme_data_provenance prov;
116 enum nvme_data_window window;
117 uint32_t offset; /* NVME_DATA_WINDOW_EXPLICIT only */
118 bool level0_prefix; /* Receive may contain only an initial prefix. */
119};
120
121/* Common origins: no claim at all, or response data at a tracked offset. */
122#define NVME_DATA_ORIGIN_NONE ((struct nvme_data_origin){ \
123 .prov = NVME_DATA_PROV_NONE, .window = NVME_DATA_WINDOW_UNKNOWN })
124#define NVME_DATA_ORIGIN_TRACKED ((struct nvme_data_origin){ \
125 .prov = NVME_DATA_PROV_RESPONSE, .window = NVME_DATA_WINDOW_TRACKED })
126
128 wmem_tree_t *pending_cmds;
129 wmem_tree_t *done_cmds;
130 wmem_tree_t *data_requests;
131 wmem_tree_t *data_responses;
132 wmem_tree_t *data_offsets;
133 uint16_t qid;
134};
135
136bool nvme_admin_opcode_is_reserved(uint8_t opcode);
137
138enum nvme_feat_xfer {
139 NVME_FEAT_XFER_UNKNOWN, /* reserved, vendor specific or dword-dependent */
140 NVME_FEAT_XFER_NONE, /* no data buffer (Base 2.4 Figure 466) */
141 NVME_FEAT_XFER_DATA, /* data buffer; *size when fixed, else 0 */
142};
143
144/* Whether Set (get=false) or Get Features with these dwords uses a data
145 * buffer, and its size in bytes when the structure is fixed (0 = not known). */
146enum nvme_feat_xfer nvme_feature_transfer(uint8_t fid, bool get, uint8_t sel,
147 uint32_t cdw11, uint32_t cdw13,
148 uint32_t *size);
149
150/* True when tree holds a decoded item: a node with children or one that is
151 * not the generic NVMe Data wrapper. */
152bool nvme_data_tree_has_fields(proto_tree *tree);
153
154#define NVME_CMD_MAX_TRS (16)
155
157 uint32_t cmd_pkt_num; /* pkt number of the cmd */
158 uint32_t cqe_pkt_num; /* pkt number of the cqe */
159
160 uint32_t data_req_pkt_num;
161 uint32_t data_tr_pkt_num[NVME_CMD_MAX_TRS];
162 uint32_t first_tr_psn;
163
164 nstime_t cmd_start_time;
165 nstime_t cmd_end_time;
166 uint32_t tr_bytes; /* bytes transferred so far */
167 bool fabric; /* indicate whether cmd fabric type or not */
168
169 union {
170 struct {
171 uint8_t cns;
172 uint8_t csi;
173 } cmd_identify;
174 struct {
175 uint64_t off;
176 unsigned records;
177 bool records_valid; /* 'records' was read from the page (NAGD may legally be 0). */
178 unsigned tr_rcrd_id;
179 unsigned tr_off;
180 unsigned tr_sub_entries;
181 /* Page offset at which the last walked window ended; 0 if none
182 * did or the walk lost its framing. */
183 uint32_t tr_next_off;
184 /* NUMDU:NUMDL, 0's based; tells a whole transfer from an MI window. */
185 uint32_t numd;
186 /* LSI (CDW11 31:16): the only subject of Figures 222 and 224. */
187 uint16_t lsi;
188 uint8_t lid;
189 uint8_t csi; /* CDW14 31:24; names CSI-specific LIDs. */
190 uint8_t tr_type;
191 bool ot; /* Offset Type (CDW14 bit 23): 'off' is an index, not a byte offset. */
192 /* A Discovery read with LSP EXTDLPE set (Base 2.3 Figure 309): its
193 * records may be Extended entries, so each may be TEL bytes long. */
194 bool extdlpe;
195 uint8_t lsp; /* CDW10 bits 14:08 */
196 /* Persistent Event Log reporting-context identity (an NVMe-MI
197 * endpoint), or NULL: event framing is then not carried across
198 * commands. */
199 const void *scope;
200 /* Set per data block: the bytes are vouched response data. */
201 bool retain;
202 } get_logpage;
203 struct {
204 uint8_t fid;
205 uint32_t cdw11;
206 uint32_t cdw13;
207 uint8_t response_count;
208 bool response_count_valid;
209 /* Get Features Select (CDW10 bits 10:08); 011b makes Dword 0 the
210 * supported capabilities (NVMe Base 2.3 Figure 199). */
211 uint8_t sel;
212 } set_features;
213 struct {
214 /* Dword 11: Security Send Transfer Length or Receive Allocation
215 * Length; 0 when the request was not seen. */
216 uint32_t xfer_len;
217 const void *scope; /* Stable transport/endpoint identity, never a command-slot key. */
218 uint16_t controller;
219 /* MI requests retain both integrity and the Security transfer
220 * contract here; responses may narrow, never replace, validity. */
221 bool state_valid;
222 /* Security Send/Receive CDW10 selectors, for data dispatch. */
223 uint16_t spsp; /* SP Specific (SPSP1:SPSP0); the ComID for TCG */
224 uint8_t secp; /* Security Protocol */
225 } security;
226 struct {
227 union {
228 struct {
229 uint32_t offset;
230 uint8_t attr; /* ATTRIB.PRS, Base 2.3 Figure 585 */
231 } prop_get;
232 struct {
233 uint16_t qid;
234 } cnct;
235 };
236 uint8_t fctype; /* fabric cmd type */
237 } fabric_cmd;
238 struct {
239 /* NS Management SEL, Capacity Management OPER or Virtualization
240 * Management ACT (CDW10 03:00): selects the CQE Dword 0 layout. */
241 uint8_t sel;
242 } admin_mgmt;
243 } cmd_ctx;
244 uint8_t opcode;
245};
246
247extern int hf_nvmeof_cmd_pkt;
248extern int hf_nvmeof_data_req;
249
250const char *get_nvmeof_cmd_string(uint8_t fctype);
251
252void
253nvme_publish_qid(proto_tree *tree, int field_index, uint16_t qid);
254
255void
256nvme_publish_cmd_latency(proto_tree *tree, struct nvme_cmd_ctx *cmd_ctx,
257 int field_index);
258void
259nvme_publish_to_cmd_link(proto_tree *tree, tvbuff_t *tvb,
260 int hf_index, struct nvme_cmd_ctx *cmd_ctx);
261void
262nvme_publish_to_cqe_link(proto_tree *tree, tvbuff_t *tvb,
263 int hf_index, struct nvme_cmd_ctx *cmd_ctx);
264void
265nvme_publish_to_data_req_link(proto_tree *tree, tvbuff_t *tvb,
266 int hf_index, struct nvme_cmd_ctx *cmd_ctx);
267void
268nvme_publish_to_data_resp_link(proto_tree *tree, tvbuff_t *tvb,
269 int hf_index, struct nvme_cmd_ctx *cmd_ctx);
270void
271nvme_publish_link(proto_tree *tree, tvbuff_t *tvb, int hf_index,
272 uint32_t pkt_no, bool zero_ok);
273
274void nvme_update_cmd_end_info(packet_info *pinfo, struct nvme_cmd_ctx *cmd_ctx);
275
276void
277nvme_add_cmd_to_pending_list(packet_info *pinfo, struct nvme_q_ctx *q_ctx,
278 struct nvme_cmd_ctx *cmd_ctx,
279 void *ctx, uint16_t cmd_id);
280void* nvme_lookup_cmd_in_pending_list(struct nvme_q_ctx *q_ctx, uint16_t cmd_id);
281
283{
284 uint64_t addr;
285 uint32_t key;
286 uint32_t size;
287};
288
289void
290dissect_nvmeof_fabric_cmd(tvbuff_t *nvme_tvb, packet_info *pinfo, proto_tree *nvme_tree,
291 struct nvme_q_ctx *q_ctx, struct nvme_cmd_ctx *cmd, unsigned off, bool link_data_req);
292void
293dissect_nvmeof_cmd_data(tvbuff_t *data_tvb, packet_info *pinfo, proto_tree *data_tree,
294 unsigned pkt_off, struct nvme_q_ctx *q_ctx, struct nvme_cmd_ctx *cmd, unsigned len);
295void
296dissect_nvmeof_fabric_cqe(tvbuff_t *nvme_tvb, packet_info *pinfo,
297 proto_tree *nvme_tree,
298 struct nvme_cmd_ctx *cmd_ctx, unsigned off);
299
300void
301nvme_add_data_request(struct nvme_q_ctx *q_ctx, struct nvme_cmd_ctx *cmd_ctx,
302 struct keyed_data_req *req);
303
304struct nvme_cmd_ctx*
305nvme_lookup_data_request(struct nvme_q_ctx *q_ctx, struct keyed_data_req *req);
306
307void
308nvme_add_data_tr_pkt(struct nvme_q_ctx *q_ctx,
309 struct nvme_cmd_ctx *cmd_ctx, uint32_t rkey, uint32_t frame_num);
310struct nvme_cmd_ctx*
311nvme_lookup_data_tr_pkt(struct nvme_q_ctx *q_ctx,
312 uint32_t rkey, uint32_t frame_num);
313
314void
315nvme_add_data_tr_off(struct nvme_q_ctx *q_ctx, uint32_t off, uint32_t frame_num);
316
317uint32_t
318nvme_lookup_data_tr_off(struct nvme_q_ctx *q_ctx, uint32_t frame_num);
319
320void
321nvme_add_cmd_cqe_to_done_list(struct nvme_q_ctx *q_ctx,
322 struct nvme_cmd_ctx *cmd_ctx, uint16_t cmd_id);
323void*
324nvme_lookup_cmd_in_done_list(packet_info *pinfo, struct nvme_q_ctx *q_ctx,
325 uint16_t cmd_id, bool is_cqe);
326
327void dissect_nvme_cmd_sgl(tvbuff_t *cmd_tvb, proto_tree *cmd_tree, int field_index,
328 struct nvme_q_ctx *q_ctx, struct nvme_cmd_ctx *cmd_ctx, unsigned cmd_off, bool visited);
329
330void
331dissect_nvme_cmd(tvbuff_t *nvme_tvb, packet_info *pinfo, proto_tree *root_tree,
332 struct nvme_q_ctx *q_ctx, struct nvme_cmd_ctx *cmd_ctx);
333
334void nvme_update_transfer_request(packet_info *pinfo, struct nvme_cmd_ctx *cmd_ctx, struct nvme_q_ctx *q_ctx);
335
336void
337dissect_nvme_data_response(tvbuff_t *nvme_tvb, packet_info *pinfo, proto_tree *root_tree,
338 struct nvme_q_ctx *q_ctx, struct nvme_cmd_ctx *cmd_ctx, unsigned len, bool is_inline,
339 enum nvme_data_direction dir, struct nvme_data_origin origin);
340
341void
342dissect_nvme_cqe(tvbuff_t *nvme_tvb, packet_info *pinfo, proto_tree *root_tree,
343 struct nvme_q_ctx *q_ctx, struct nvme_cmd_ctx *cmd_ctx);
344
349const char *
350nvme_get_opcode_string(uint8_t opcode, uint16_t qid);
351
352/* Admin opcode naming with an explicit I/O Command Set Identifier. */
353const char *
354nvme_get_admin_opcode_string(uint8_t opcode, uint8_t csi);
355
356/* CSTS.SHST shutdown-status names; shared with the NVMe-MI CHDS decode. */
357extern const value_string shst_table[];
358
359/* Decode Admin SQE CDW10-CDW15 (SQE offset 40) for cmd_ctx->opcode,
360 * filling cmd_ctx; shared with NVMe-MI. */
361void
362nvme_dissect_admin_sqe_cdws(tvbuff_t *sqe_tvb, packet_info *pinfo,
363 proto_tree *tree, struct nvme_cmd_ctx *cmd_ctx);
364
365/* Decode Admin CQE Dword 0 at dw0_off for cmd_ctx->opcode; shared with
366 * NVMe-MI. */
367void
368nvme_dissect_admin_cqe_dw0(tvbuff_t *nvme_tvb, int dw0_off, proto_tree *cqe_tree,
369 uint16_t status, struct nvme_cmd_ctx *cmd_ctx);
370
371/* Decode Admin CQE Dword 1 fields at dw1_off for cmd_ctx->opcode, where
372 * the command defines them; shared with NVMe-MI. */
373void
374nvme_dissect_admin_cqe_dw1(tvbuff_t *nvme_tvb, int dw1_off, proto_tree *cqe_tree,
375 uint16_t status, struct nvme_cmd_ctx *cmd_ctx);
376
377/* CQE Status Field word alone, for transports without the full CQE layout
378 * (Base 2.3 Fig 100); nvmeof selects the fabrics rendering. */
379void
380nvme_dissect_cqe_status(tvbuff_t *nvme_tvb, packet_info *pinfo, proto_tree *cqe_tree,
381 unsigned status_off, bool nvmeof);
382
383/* As nvme_dissect_cqe_status() for an Admin command completion: a Command
384 * Specific Status Code is also checked against the command that the
385 * NVM Express Base 2.4 Figure 104 lists it for. */
386void
387nvme_dissect_admin_cqe_status(tvbuff_t *nvme_tvb, packet_info *pinfo, proto_tree *cqe_tree,
388 unsigned status_off, uint8_t opcode);
389
390/* The 'data' of the "nvme.security.secp" table. Only a first window
391 * (offset 0) is dispatched, a short Receive one included; xfer_len tells a
392 * short transfer from a bad length. Sub-dissectors must reject NULL data. */
394 bool send; /* true = Security Send payload (host to controller) */
395 uint8_t secp; /* Security Protocol */
396 uint16_t spsp; /* SP Specific (SPSP1:SPSP0); the ComID for TCG */
397 uint32_t xfer_len; /* Dword 11 (Send: TL, Receive: AL); 0 if unknown */
398 const void *scope;
399 uint16_t controller;
400 bool state_valid; /* Complete, trustworthy transport data may advance streams. */
401 /* Receive only: the window may legally end before AL (Level 0 prefix). */
402 bool level0_prefix;
403};
404
405/* The security info a Security Send/Receive command recorded. */
406static inline struct nvme_security_info
407nvme_security_info_of(const struct nvme_cmd_ctx *cmd_ctx, bool send)
408{
409 return (struct nvme_security_info){
410 .send = send,
411 .secp = cmd_ctx->cmd_ctx.security.secp,
412 .spsp = cmd_ctx->cmd_ctx.security.spsp,
413 .xfer_len = cmd_ctx->cmd_ctx.security.xfer_len,
414 .scope = cmd_ctx->cmd_ctx.security.scope,
415 .controller = cmd_ctx->cmd_ctx.security.controller,
416 .state_valid = cmd_ctx->cmd_ctx.security.state_valid,
417 };
418}
419
426bool
427nvme_dissect_admin_data_resp(tvbuff_t *nvme_tvb, packet_info *pinfo,
428 proto_tree *cmd_tree, struct nvme_cmd_ctx *cmd_ctx,
429 unsigned off, unsigned len,
430 struct nvme_data_origin origin,
431 enum nvme_data_direction dir);
432
433/* Tells if the command whose SQE starts at off implies an Admin queue, for
434 * guessing the queue type when the Connect was not captured. */
435bool
436nvme_cmd_implies_admin_queue(tvbuff_t *tvb, unsigned off);
437
438/* Base 2.3 Fig 138, also used by MI 2.1 DTYP 02h. Returns the number of
439 * bytes occupied by the count and complete selected identifiers. */
440unsigned nvme_dissect_controller_list(tvbuff_t *tvb, packet_info *pinfo,
441 proto_tree *tree, unsigned off, unsigned len, int hf_count, int hf_id);
442
443#endif
444
445/*
446 * Editor modelines - https://www.wireshark.org/tools/modelines.html
447 *
448 * Local variables:
449 * c-basic-offset: 4
450 * tab-width: 8
451 * indent-tabs-mode: nil
452 * End:
453 *
454 * vi: set shiftwidth=4 tabstop=8 expandtab:
455 * :indentSize=4:tabSize=8:noTabs=true:
456 */
struct _packet_info packet_info
Represents the metadata and indexing information for a single captured frame.
struct _wmem_tree_t wmem_tree_t
Opaque type representing a red-black tree in the wmem system.
Definition wmem_tree.h:49
Definition packet-nvme.h:283
Definition nstime.h:26
Definition packet-nvme.h:156
Definition packet-nvme.h:114
Definition packet-nvme.h:127
Definition packet-nvme.h:393
struct _value_string value_string
Mapping between a 32-bit integer value and its string representation.