Wireshark  4.3.0
The Wireshark network protocol analyzer
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 
27 struct nvme_q_ctx {
28  wmem_tree_t *pending_cmds;
29  wmem_tree_t *done_cmds;
30  wmem_tree_t *data_requests;
31  wmem_tree_t *data_responses;
32  wmem_tree_t *data_offsets;
33  guint16 qid;
34 };
35 
36 #define NVME_CMD_MAX_TRS (16)
37 
38 struct nvme_cmd_ctx {
39  guint32 cmd_pkt_num; /* pkt number of the cmd */
40  guint32 cqe_pkt_num; /* pkt number of the cqe */
41 
42  guint32 data_req_pkt_num;
43  guint32 data_tr_pkt_num[NVME_CMD_MAX_TRS];
44  guint32 first_tr_psn;
45 
46  nstime_t cmd_start_time;
47  nstime_t cmd_end_time;
48  guint32 tr_bytes; /* bytes transferred so far */
49  gboolean fabric; /* indicate whether cmd fabric type or not */
50 
51  union {
52  struct {
53  guint16 cns;
54  } cmd_identify;
55  struct {
56  guint records;
57  guint tr_rcrd_id;
58  guint tr_off;
59  guint tr_sub_entries;
60  guint16 lsi;
61  guint8 lid;
62  guint8 lsp;
63  guint64 off;
64  guint8 uid_idx;
65  } get_logpage;
66  struct {
67  guint8 fid;
68  } set_features;
69  struct {
70  union {
71  struct {
72  guint8 offset;
73  } prop_get;
74  struct {
75  uint16_t qid;
76  } cnct;
77  };
78  guint8 fctype; /* fabric cmd type */
79  } fabric_cmd;
80  } cmd_ctx;
81  guint8 opcode;
82 };
83 
84 extern int hf_nvmeof_cmd_pkt;
85 extern int hf_nvmeof_data_req;
86 
87 const gchar *get_nvmeof_cmd_string(guint8 fctype);
88 
89 void
90 nvme_publish_qid(proto_tree *tree, int field_index, guint16 qid);
91 
92 void
93 nvme_publish_cmd_latency(proto_tree *tree, struct nvme_cmd_ctx *cmd_ctx,
94  int field_index);
95 void
96 nvme_publish_to_cmd_link(proto_tree *tree, tvbuff_t *tvb,
97  int hf_index, struct nvme_cmd_ctx *cmd_ctx);
98 void
99 nvme_publish_to_cqe_link(proto_tree *tree, tvbuff_t *tvb,
100  int hf_index, struct nvme_cmd_ctx *cmd_ctx);
101 void
102 nvme_publish_to_data_req_link(proto_tree *tree, tvbuff_t *tvb,
103  int hf_index, struct nvme_cmd_ctx *cmd_ctx);
104 void
105 nvme_publish_to_data_resp_link(proto_tree *tree, tvbuff_t *tvb,
106  int hf_index, struct nvme_cmd_ctx *cmd_ctx);
107 void
108 nvme_publish_link(proto_tree *tree, tvbuff_t *tvb, int hf_index,
109  guint32 pkt_no, gboolean zero_ok);
110 
111 void nvme_update_cmd_end_info(packet_info *pinfo, struct nvme_cmd_ctx *cmd_ctx);
112 
113 void
114 nvme_add_cmd_to_pending_list(packet_info *pinfo, struct nvme_q_ctx *q_ctx,
115  struct nvme_cmd_ctx *cmd_ctx,
116  void *ctx, guint16 cmd_id);
117 void* nvme_lookup_cmd_in_pending_list(struct nvme_q_ctx *q_ctx, guint16 cmd_id);
118 
120 {
121  guint64 addr;
122  guint32 key;
123  guint32 size;
124 };
125 
126 void
127 dissect_nvmeof_fabric_cmd(tvbuff_t *nvme_tvb, packet_info *pinfo, proto_tree *nvme_tree,
128  struct nvme_q_ctx *q_ctx, struct nvme_cmd_ctx *cmd, guint off, gboolean link_data_req);
129 void
130 dissect_nvmeof_cmd_data(tvbuff_t *data_tvb, packet_info *pinfo, proto_tree *data_tree,
131  guint pkt_off, struct nvme_q_ctx *q_ctx, struct nvme_cmd_ctx *cmd, guint len);
132 void
133 dissect_nvmeof_fabric_cqe(tvbuff_t *nvme_tvb, packet_info *pinfo,
134  proto_tree *nvme_tree,
135  struct nvme_cmd_ctx *cmd_ctx, guint off);
136 
137 void
138 nvme_add_data_request(struct nvme_q_ctx *q_ctx, struct nvme_cmd_ctx *cmd_ctx,
139  struct keyed_data_req *req);
140 
141 struct nvme_cmd_ctx*
142 nvme_lookup_data_request(struct nvme_q_ctx *q_ctx, struct keyed_data_req *req);
143 
144 void
145 nvme_add_data_tr_pkt(struct nvme_q_ctx *q_ctx,
146  struct nvme_cmd_ctx *cmd_ctx, guint32 rkey, guint32 frame_num);
147 struct nvme_cmd_ctx*
148 nvme_lookup_data_tr_pkt(struct nvme_q_ctx *q_ctx,
149  guint32 rkey, guint32 frame_num);
150 
151 void
152 nvme_add_data_tr_off(struct nvme_q_ctx *q_ctx, guint32 off, guint32 frame_num);
153 
154 guint32
155 nvme_lookup_data_tr_off(struct nvme_q_ctx *q_ctx, guint32 frame_num);
156 
157 void
158 nvme_add_cmd_cqe_to_done_list(struct nvme_q_ctx *q_ctx,
159  struct nvme_cmd_ctx *cmd_ctx, guint16 cmd_id);
160 void*
161 nvme_lookup_cmd_in_done_list(packet_info *pinfo, struct nvme_q_ctx *q_ctx,
162  guint16 cmd_id);
163 
164 void dissect_nvme_cmd_sgl(tvbuff_t *cmd_tvb, proto_tree *cmd_tree, int field_index,
165  struct nvme_q_ctx *q_ctx, struct nvme_cmd_ctx *cmd_ctx, guint cmd_off, gboolean visited);
166 
167 void
168 dissect_nvme_cmd(tvbuff_t *nvme_tvb, packet_info *pinfo, proto_tree *root_tree,
169  struct nvme_q_ctx *q_ctx, struct nvme_cmd_ctx *cmd_ctx);
170 
171 void nvme_update_transfer_request(packet_info *pinfo, struct nvme_cmd_ctx *cmd_ctx, struct nvme_q_ctx *q_ctx);
172 
173 void
174 dissect_nvme_data_response(tvbuff_t *nvme_tvb, packet_info *pinfo, proto_tree *root_tree,
175  struct nvme_q_ctx *q_ctx, struct nvme_cmd_ctx *cmd_ctx, guint len, gboolean is_inline);
176 
177 void
178 dissect_nvme_cqe(tvbuff_t *nvme_tvb, packet_info *pinfo, proto_tree *root_tree,
179  struct nvme_q_ctx *q_ctx, struct nvme_cmd_ctx *cmd_ctx);
180 
185 const gchar *
186 nvme_get_opcode_string(guint8 opcode, guint16 qid);
187 
188 /*
189  * Tells if opcode can be an opcode of io queue.
190  * Used to "Guess" queue type for nvme-tcp in case that "connect"
191  * command was not recorded
192  */
193 int
194 nvme_is_io_queue_opcode(guint8 opcode);
195 
196 #endif
197 
198 /*
199  * Editor modelines - https://www.wireshark.org/tools/modelines.html
200  *
201  * Local variables:
202  * c-basic-offset: 4
203  * tab-width: 8
204  * indent-tabs-mode: nil
205  * End:
206  *
207  * vi: set shiftwidth=4 tabstop=8 expandtab:
208  * :indentSize=4:tabSize=8:noTabs=true:
209  */
Definition: packet_info.h:44
Definition: proto.h:904
Definition: wmem_tree-int.h:48
Definition: packet-nvme.h:120
Definition: nstime.h:26
Definition: packet-nvme.h:38
Definition: packet-nvme.h:27
Definition: tvbuff-int.h:35