Coverage Report

Created: 2026-01-02 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-opa-snc.c
Line
Count
Source
1
/* packet-opa-snc.c
2
 * Routines for Omni-Path SnC header dissection
3
 * Copyright (c) 2016, Intel Corporation.
4
 *
5
 * Wireshark - Network traffic analyzer
6
 * By Gerald Combs <gerald@wireshark.org>
7
 * Copyright 1998 Gerald Combs
8
 *
9
 * SPDX-License-Identifier: GPL-2.0-or-later
10
 */
11
12
#include "config.h"
13
14
#include <epan/packet.h>
15
#include <epan/expert.h>
16
#include <epan/tfs.h>
17
#include <wsutil/array.h>
18
#include <wiretap/erf_record.h>
19
20
void proto_reg_handoff_opa_snc(void);
21
void proto_register_opa_snc(void);
22
23
static const value_string vals_opa_snc_direction[] = {
24
    { 0, "Outbound" },
25
    { 1, "Inbound" },
26
    { 2, "Internal Debugging Tool" },
27
    { 0, NULL }
28
};
29
/* PBC */
30
static const true_false_string tfs_opa_snc_pbc_isBypass = {
31
    "Bypass (8B/10B/16B) Packet",
32
    "9B Packet"
33
};
34
static const value_string vals_opa_snc_pbc_insertHcrc[] = {
35
    { 0x0, "KDETH Hcrc calculated assuming GRH is not present" },
36
    { 0x1, "KDETH Hcrc calculated assuming GRH is present" },
37
    { 0x2, "KDETH Hcrc is not inserted" },
38
    { 0x3, "Reserved" },
39
    { 0, NULL }
40
};
41
/* RHF */
42
static const value_string vals_opa_snc_rhf_rcvtypeerr[] = {
43
    { 0x0, "No Error" },
44
    { 0x1, "OpCode Error" },
45
    { 0x2, "KDETH Min Length Error" },
46
    { 0x3, "KDETH Hcrc Error" },
47
    { 0x4, "KDETH Version Error" },
48
    { 0x5, "Context Error" },
49
    { 0x6, "KDETH TID Error" },
50
    { 0x7, "Reserved" },
51
    { 0, NULL }
52
};
53
static const value_string vals_opa_snc_rhf_rcvtype[] = {
54
    { 0, "Expected Receive" },
55
    { 1, "Eager Receive" },
56
    { 2, "IB" },
57
    { 3, "error" },
58
    { 4, "bypass" },
59
    { 0, NULL }
60
};
61
62
/* Wireshark ID */
63
static int proto_opa_snc;
64
65
/* Variables to hold expansion values between packets */
66
static int ett_snc;
67
static int ett_sncpbc;
68
static int ett_sncrhf;
69
70
/* SnC Fields */
71
static int hf_opa_snc_direction;
72
static int hf_opa_snc_portnumber;
73
static int hf_opa_snc_Reserved16;
74
static int hf_opa_snc_Reserved32;
75
static int hf_opa_snc_Reserved64;
76
static int hf_opa_snc_pbc_reserved_63_48;
77
static int hf_opa_snc_pbc_pbcstaticratecontrolcnt;
78
static int hf_opa_snc_pbc_pbcintr;
79
static int hf_opa_snc_pbc_pbcdcinfo;
80
static int hf_opa_snc_pbc_pbctestebp;
81
static int hf_opa_snc_pbc_pbcpacketbypass;
82
static int hf_opa_snc_pbc_pbcinserthcrc;
83
static int hf_opa_snc_pbc_pbccreditreturn;
84
static int hf_opa_snc_pbc_pbcinsertbypassicrc;
85
static int hf_opa_snc_pbc_pbctestbadicrc;
86
static int hf_opa_snc_pbc_pbcfecn;
87
static int hf_opa_snc_pbc_reserved_21_16;
88
static int hf_opa_snc_pbc_pbcvl;
89
static int hf_opa_snc_pbc_pbclengthdws;
90
static int * const _snc_pbc_1[] = {
91
    &hf_opa_snc_pbc_reserved_63_48,
92
    &hf_opa_snc_pbc_pbcstaticratecontrolcnt,
93
    NULL
94
};
95
static int * const _snc_pbc_2[] = {
96
    &hf_opa_snc_pbc_pbcintr,
97
    &hf_opa_snc_pbc_pbcdcinfo,
98
    &hf_opa_snc_pbc_pbctestebp,
99
    &hf_opa_snc_pbc_pbcpacketbypass,
100
    &hf_opa_snc_pbc_pbcinserthcrc,
101
    &hf_opa_snc_pbc_pbccreditreturn,
102
    &hf_opa_snc_pbc_pbcinsertbypassicrc,
103
    &hf_opa_snc_pbc_pbctestbadicrc,
104
    &hf_opa_snc_pbc_pbcfecn,
105
    &hf_opa_snc_pbc_reserved_21_16,
106
    &hf_opa_snc_pbc_pbcvl,
107
    &hf_opa_snc_pbc_pbclengthdws,
108
    NULL
109
};
110
static int hf_opa_snc_rhf_icrcerr;
111
static int hf_opa_snc_rhf_reserved_62;
112
static int hf_opa_snc_rhf_eccerr;
113
static int hf_opa_snc_rhf_lenerr;
114
static int hf_opa_snc_rhf_tiderr;
115
static int hf_opa_snc_rhf_rcvtypeerr;
116
static int hf_opa_snc_rhf_dcerr;
117
static int hf_opa_snc_rhf_dcuncerr;
118
static int hf_opa_snc_rhf_khdrlenerr;
119
static int hf_opa_snc_rhf_hdrqoffset;
120
static int hf_opa_snc_rhf_egroffset;
121
static int hf_opa_snc_rhf_rcvseq;
122
static int hf_opa_snc_rhf_dcinfo;
123
static int hf_opa_snc_rhf_egrindex;
124
static int hf_opa_snc_rhf_useegrbfr;
125
static int hf_opa_snc_rhf_rcvtype;
126
static int hf_opa_snc_rhf_pktlen;
127
static int * const _snc_rhf_1[] = {
128
    &hf_opa_snc_rhf_icrcerr,
129
    &hf_opa_snc_rhf_reserved_62,
130
    &hf_opa_snc_rhf_eccerr,
131
    &hf_opa_snc_rhf_lenerr,
132
    &hf_opa_snc_rhf_tiderr,
133
    &hf_opa_snc_rhf_rcvtypeerr,
134
    &hf_opa_snc_rhf_dcerr,
135
    &hf_opa_snc_rhf_dcuncerr,
136
    &hf_opa_snc_rhf_khdrlenerr,
137
    &hf_opa_snc_rhf_hdrqoffset,
138
    &hf_opa_snc_rhf_egroffset,
139
    NULL
140
};
141
static int * const _snc_rhf_2[] = {
142
    &hf_opa_snc_rhf_rcvseq,
143
    &hf_opa_snc_rhf_dcinfo,
144
    &hf_opa_snc_rhf_egrindex,
145
    &hf_opa_snc_rhf_useegrbfr,
146
    &hf_opa_snc_rhf_rcvtype,
147
    &hf_opa_snc_rhf_pktlen,
148
    NULL
149
};
150
151
static expert_field ei_opa_snc_nobypass;
152
153
static void cf_opa_snc_dw_to_b(char *buf, uint32_t value)
154
0
{
155
0
    snprintf(buf, ITEM_LABEL_LENGTH, "%u DWORDS, %u Bytes", value, value * 4);
156
0
}
157
static void cf_opa_snc_qw_to_b(char *buf, uint32_t value)
158
0
{
159
0
    snprintf(buf, ITEM_LABEL_LENGTH, "%u QWORDS, %u Bytes", value, value * 8);
160
0
}
161
162
/* Dissector Declarations */
163
static dissector_handle_t opa_snc_handle;
164
static dissector_handle_t opa_9b_handle;
165
166
static int dissect_opa_snc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
167
0
{
168
0
    int offset = 0;    /* Current Offset */
169
170
0
    bool isBypass = true;  /* Tracks if we are parsing a bypass packet or Not */
171
0
    uint8_t Direction = tvb_get_uint8(tvb, offset + 1);
172
0
    uint64_t RHF_PBC;
173
0
    proto_item *SnC_item;
174
0
    proto_tree * SnC_tree,*PBC_tree,*RHF_tree;
175
176
0
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "Omni-Path");
177
0
    col_clear(pinfo->cinfo, COL_INFO);
178
179
0
    tree = proto_tree_get_parent_tree(tree);
180
181
0
    SnC_item = proto_tree_add_item(tree, proto_opa_snc, tvb, offset, 16, ENC_NA);
182
0
    SnC_tree = proto_item_add_subtree(SnC_item, ett_snc);
183
184
0
    proto_tree_add_item(SnC_tree, hf_opa_snc_portnumber, tvb, offset, 1, ENC_LITTLE_ENDIAN);
185
0
    offset += 1;
186
0
    proto_tree_add_item(SnC_tree, hf_opa_snc_direction, tvb, offset, 1, ENC_LITTLE_ENDIAN);
187
0
    offset += 1;
188
0
    proto_tree_add_item(SnC_tree, hf_opa_snc_Reserved16, tvb, offset, 2, ENC_LITTLE_ENDIAN);
189
0
    offset += 2;
190
0
    proto_tree_add_item(SnC_tree, hf_opa_snc_Reserved32, tvb, offset, 4, ENC_LITTLE_ENDIAN);
191
0
    offset += 4;
192
193
0
    RHF_PBC = tvb_get_letoh64(tvb, offset);
194
0
    switch (Direction) {
195
0
    case 0:
196
0
        PBC_tree = proto_tree_add_subtree(SnC_tree, tvb, offset, 8, ett_sncpbc, NULL, "PBC - Per Buffer Control");
197
0
        proto_tree_add_bitmask_list(PBC_tree, tvb, offset + 4, 4, _snc_pbc_1, ENC_LITTLE_ENDIAN);
198
0
        proto_tree_add_bitmask_list(PBC_tree, tvb, offset, 4, _snc_pbc_2, ENC_LITTLE_ENDIAN);
199
0
        isBypass = (((RHF_PBC >> 28) & 1) == 1);
200
0
        break;
201
0
    case 1:
202
0
        RHF_tree = proto_tree_add_subtree(SnC_tree, tvb, offset, 8, ett_sncrhf, NULL, "RHF - Receive Header Flags");
203
0
        proto_tree_add_bitmask_list(RHF_tree, tvb, offset + 4, 4, _snc_rhf_1, ENC_LITTLE_ENDIAN);
204
0
        proto_tree_add_bitmask_list(RHF_tree, tvb, offset, 4, _snc_rhf_2, ENC_LITTLE_ENDIAN);
205
0
        isBypass = (((RHF_PBC >> 12) & 7) == 4);
206
0
        break;
207
0
    case 2:     /* For use with internal debugging tools */
208
0
        proto_tree_add_item(SnC_tree, hf_opa_snc_Reserved64, tvb, offset, 8, ENC_LITTLE_ENDIAN);
209
0
        isBypass = false;
210
0
        break;
211
0
    default:
212
0
        isBypass = false;
213
0
    }
214
0
    offset += 8;
215
216
0
    if (isBypass) {
217
        /* Bypass packets not implemented in this version */
218
0
        expert_add_info(pinfo, NULL, &ei_opa_snc_nobypass);
219
0
    } else {
220
0
        call_dissector(opa_9b_handle, tvb_new_subset_remaining(tvb, offset), pinfo, tree);
221
0
    }
222
0
    return tvb_captured_length(tvb);
223
0
}
224
225
void proto_register_opa_snc(void)
226
14
{
227
14
    expert_module_t *expert_opa_snc;
228
229
14
    static hf_register_info hf[] = {
230
14
        { &hf_opa_snc_direction, {
231
14
                "Direction", "opa.snc.direction",
232
14
                FT_UINT8, BASE_HEX, VALS(vals_opa_snc_direction), 0x0, NULL, HFILL }
233
14
        },
234
14
        { &hf_opa_snc_portnumber, {
235
14
                "Port Number", "opa.snc.portnumber",
236
14
                FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL }
237
14
        },
238
14
        { &hf_opa_snc_Reserved32, {
239
14
                "Reserved (32 bits)", "opa.snc.reserved32",
240
14
                FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL }
241
14
        },
242
14
        { &hf_opa_snc_Reserved64, {
243
14
                "Reserved (64 bits)", "opa.snc.reserved64",
244
14
                FT_UINT64, BASE_HEX, NULL, 0x0, NULL, HFILL }
245
14
        },
246
14
        { &hf_opa_snc_Reserved16, {
247
14
                "Reserved (16 bits)", "opa.snc.reserved16",
248
14
                FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
249
14
        },
250
14
        { &hf_opa_snc_pbc_reserved_63_48, {
251
14
                "Reserved (16 bits)", "opa.snc.pbc.reserved_63_48",
252
14
                FT_UINT32, BASE_HEX, NULL, 0xFFFF0000, NULL, HFILL }
253
14
        },
254
14
        { &hf_opa_snc_pbc_pbcstaticratecontrolcnt, {
255
14
                "Static Rate Control Counter", "opa.snc.pbc.pbcstaticratecontrolcnt",
256
14
                FT_UINT32, BASE_HEX, NULL, 0x0000FFFF, NULL, HFILL }
257
14
        },
258
14
        { &hf_opa_snc_pbc_pbcintr, {
259
14
                "Interrupt", "opa.snc.pbc.pbcintr",
260
14
                FT_BOOLEAN, 32, TFS(&tfs_set_notset), 0x80000000, NULL, HFILL }
261
14
        },
262
14
        { &hf_opa_snc_pbc_pbcdcinfo, {
263
14
                "DC Info", "opa.snc.pbc.pbcdcinfo",
264
14
                FT_BOOLEAN, 32, TFS(&tfs_set_notset), 0x40000000, NULL, HFILL }
265
14
        },
266
14
        { &hf_opa_snc_pbc_pbctestebp, {
267
14
                "Test End Bad Packet", "opa.snc.pbc.pbctestebp",
268
14
                FT_BOOLEAN, 32, TFS(&tfs_set_notset), 0x20000000, NULL, HFILL }
269
14
        },
270
14
        { &hf_opa_snc_pbc_pbcpacketbypass, {
271
14
                "Packet Type", "opa.snc.pbc.pbcpacketbypass",
272
14
                FT_BOOLEAN, 32, TFS(&tfs_opa_snc_pbc_isBypass), 0x10000000, NULL, HFILL }
273
14
        },
274
14
        { &hf_opa_snc_pbc_pbcinserthcrc, {
275
14
                "Insert Hcrc", "opa.snc.pbc.pbcinserthcrc",
276
14
                FT_UINT32, BASE_HEX, VALS(vals_opa_snc_pbc_insertHcrc), 0x0C000000, NULL, HFILL }
277
14
        },
278
14
        { &hf_opa_snc_pbc_pbccreditreturn, {
279
14
                "Request Credit Return", "opa.snc.pbc.pbccreditreturn",
280
14
                FT_BOOLEAN, 32, TFS(&tfs_set_notset), 0x02000000, NULL, HFILL }
281
14
        },
282
14
        { &hf_opa_snc_pbc_pbcinsertbypassicrc, {
283
14
                "Insert ICRC for bypass packets", "opa.snc.pbc.pbcinsertbypassicrc",
284
14
                FT_BOOLEAN, 32, TFS(&tfs_set_notset), 0x01000000, NULL, HFILL }
285
14
        },
286
14
        { &hf_opa_snc_pbc_pbctestbadicrc, {
287
14
                "Insert a bad ICRC", "opa.snc.pbc.pbctestbadicrc",
288
14
                FT_BOOLEAN, 32, TFS(&tfs_set_notset), 0x00800000, NULL, HFILL }
289
14
        },
290
14
        { &hf_opa_snc_pbc_pbcfecn, {
291
14
                "Set FECN bit", "opa.snc.pbc.pbcfecn",
292
14
                FT_BOOLEAN, 32, TFS(&tfs_set_notset), 0x00400000, NULL, HFILL }
293
14
        },
294
14
        { &hf_opa_snc_pbc_reserved_21_16, {
295
14
                "Reserved (6 bits)", "opa.snc.pbc.reserved_21_16",
296
14
                FT_UINT32, BASE_HEX, NULL, 0x003F0000, NULL, HFILL }
297
14
        },
298
14
        { &hf_opa_snc_pbc_pbcvl, {
299
14
                "VL", "opa.snc.pbc.pbcvl",
300
14
                FT_UINT32, BASE_DEC, NULL, 0x0000F000, NULL, HFILL }
301
14
        },
302
14
        { &hf_opa_snc_pbc_pbclengthdws, {
303
14
                "pbclengthdws", "opa.snc.pbc.pbclengthdws",
304
14
                FT_UINT32, BASE_CUSTOM, CF_FUNC(cf_opa_snc_dw_to_b), 0x00000FFF, NULL, HFILL }
305
14
        },
306
307
14
        { &hf_opa_snc_rhf_icrcerr, {
308
14
                "ICRC error", "opa.snc.rhf.icrcerr",
309
14
                FT_BOOLEAN, 32, TFS(&tfs_error_ok), 0x80000000, NULL, HFILL }
310
14
        },
311
14
        { &hf_opa_snc_rhf_reserved_62, {
312
14
                "Reserved (1 bit)", "opa.snc.rhf.reserved_62",
313
14
                FT_UINT32, BASE_HEX, NULL, 0x40000000, NULL, HFILL }
314
14
        },
315
14
        { &hf_opa_snc_rhf_eccerr, {
316
14
                "Internal memory Uncorrectable error", "opa.snc.rhf.eccerr",
317
14
                FT_BOOLEAN, 32, TFS(&tfs_error_ok), 0x20000000, NULL, HFILL }
318
14
        },
319
14
        { &hf_opa_snc_rhf_lenerr, {
320
14
                "Length Error", "opa.snc.rhf.lenerr",
321
14
                FT_BOOLEAN, 32, TFS(&tfs_error_ok), 0x10000000, NULL, HFILL }
322
14
        },
323
14
        { &hf_opa_snc_rhf_tiderr, {
324
14
                "TID Error", "opa.snc.rhf.tiderr",
325
14
                FT_BOOLEAN, 32, TFS(&tfs_error_ok), 0x08000000, NULL, HFILL }
326
14
        },
327
14
        { &hf_opa_snc_rhf_rcvtypeerr, {
328
14
                "Receive Type Error", "opa.snc.rhf.rcvtypeerr",
329
14
                FT_UINT32, BASE_HEX, VALS(vals_opa_snc_rhf_rcvtypeerr), 0x07000000, NULL, HFILL }
330
14
        },
331
14
        { &hf_opa_snc_rhf_dcerr, {
332
14
                "End Bad Packet Error", "opa.snc.rhf.dcerr",
333
14
                FT_BOOLEAN, 32, TFS(&tfs_error_ok), 0x00800000, NULL, HFILL }
334
14
        },
335
14
        { &hf_opa_snc_rhf_dcuncerr, {
336
14
                "Uncorrectable or parity error", "opa.snc.rhf.dcuncerr",
337
14
                FT_BOOLEAN, 32, TFS(&tfs_error_ok), 0x00400000, NULL, HFILL }
338
14
        },
339
14
        { &hf_opa_snc_rhf_khdrlenerr, {
340
14
                "KDETH Length Error", "opa.snc.rhf.khdrlenerr",
341
14
                FT_BOOLEAN, 32, TFS(&tfs_error_ok), 0x00200000, NULL, HFILL }
342
14
        },
343
14
        { &hf_opa_snc_rhf_hdrqoffset, {
344
14
                "Receive Header Offset", "opa.snc.rhf.hdrqoffset",
345
14
                FT_UINT32, BASE_CUSTOM, CF_FUNC(cf_opa_snc_dw_to_b), 0x001FF000, NULL, HFILL }
346
14
        },
347
14
        { &hf_opa_snc_rhf_egroffset, {
348
14
                "Eager Buffer Offset", "opa.snc.rhf.egroffset",
349
14
                FT_UINT32, BASE_CUSTOM, CF_FUNC(cf_opa_snc_qw_to_b), 0x00000FFF, NULL, HFILL }
350
14
        },
351
14
        { &hf_opa_snc_rhf_rcvseq, {
352
14
                "Receive Sequence", "opa.snc.rhf.rcvseq",
353
14
                FT_UINT32, BASE_DEC, NULL, 0xF0000000, NULL, HFILL }
354
14
        },
355
14
        { &hf_opa_snc_rhf_dcinfo, {
356
14
                "DC Info", "opa.snc.rhf.dcinfo",
357
14
                FT_BOOLEAN, 32, TFS(&tfs_set_notset), 0x08000000, NULL, HFILL }
358
14
        },
359
14
        { &hf_opa_snc_rhf_egrindex, {
360
14
                "Eager Buffer Index", "opa.snc.rhf.egrindex",
361
14
                FT_UINT32, BASE_HEX, NULL, 0x07FF0000, NULL, HFILL }
362
14
        },
363
14
        { &hf_opa_snc_rhf_useegrbfr, {
364
14
                "Use Eager Buffer", "opa.snc.rhf.useegrbfr",
365
14
                FT_BOOLEAN, 32, TFS(&tfs_set_notset), 0x00008000, NULL, HFILL }
366
14
        },
367
14
        { &hf_opa_snc_rhf_rcvtype, {
368
14
                "Packet Receive Type", "opa.snc.rhf.rcvtype",
369
14
                FT_UINT32, BASE_DEC_HEX, VALS(vals_opa_snc_rhf_rcvtype), 0x00007000, NULL, HFILL }
370
14
        },
371
14
        { &hf_opa_snc_rhf_pktlen, {
372
14
                "Packet Length", "opa.snc.rhf.pktlen",
373
14
                FT_UINT32, BASE_CUSTOM, CF_FUNC(cf_opa_snc_dw_to_b), 0x00000FFF, NULL, HFILL }
374
14
        }
375
14
    };
376
377
14
    static int *ett[] = {
378
14
        &ett_snc,
379
14
        &ett_sncpbc,
380
14
        &ett_sncrhf,
381
14
    };
382
383
14
    static ei_register_info ei[] = {
384
14
        { &ei_opa_snc_nobypass, {
385
14
                "opa.snc.nobypass", PI_PROTOCOL, PI_WARN,
386
14
                "Bypass packets not implemented in this version", EXPFILL }
387
14
        }
388
14
    };
389
390
14
    proto_opa_snc = proto_register_protocol("Intel Omni-Path SnC - Omni-Path Snoop and Capture MetaData Header", "OPA SnC", "opa.snc");
391
14
    opa_snc_handle = register_dissector("opa.snc", dissect_opa_snc, proto_opa_snc);
392
393
14
    proto_register_field_array(proto_opa_snc, hf, array_length(hf));
394
14
    proto_register_subtree_array(ett, array_length(ett));
395
396
14
    expert_opa_snc = expert_register_protocol(proto_opa_snc);
397
14
    expert_register_field_array(expert_opa_snc, ei, array_length(ei));
398
14
}
399
400
void proto_reg_handoff_opa_snc(void)
401
14
{
402
14
    opa_9b_handle = find_dissector("opa");
403
404
    /* announce an anonymous Omni-Path SnC dissector */
405
14
    dissector_add_uint("erf.types.type", ERF_TYPE_OPA_SNC, opa_snc_handle);
406
407
14
}
408
409
/*
410
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
411
 *
412
 * Local variables:
413
 * c-basic-offset: 4
414
 * tab-width: 8
415
 * indent-tabs-mode: nil
416
 * End:
417
 *
418
 * vi: set shiftwidth=4 tabstop=8 expandtab:
419
 * :indentSize=4:tabSize=8:noTabs=true:
420
 */